Re: [Pharo-users] Is there a way to know line separator for the current os?
On Mar 29, 2011, at 8:08 AM, Panu Suominen wrote:
I did not find a way to get line separator in the system independent manner. Linux uses character 10 (lf), windowses (two characters: 10, 13), and mac uses 13(not sure?). Is there already a way to do this? If not I can open a issue and propose a fix.
There is #guessDefaultLineEndConvention on MultiByteFileStream -- Marcus Denker -- http://www.marcusdenker.de INRIA Lille -- Nord Europe. Team RMoD.
2011/3/30 Marcus Denker <marcus.denker@inria.fr>:
On Mar 29, 2011, at 8:08 AM, Panu Suominen wrote:
I did not find a way to get line separator in the system independent manner. Linux uses character 10 (lf), windowses (two characters: 10, 13), and mac uses 13(not sure?). Is there already a way to do this? If not I can open a issue and propose a fix.
There is #guessDefaultLineEndConvention on MultiByteFileStream
Thanx. This seems to do the trick. -- Panu
I've spend the better time of the afternoon with trying metaprogramming with Smalltalk I finally have come up with: asciiNames := Array withAll: #(#nul #soh #stx #etx #eot #enq #ack #bel #bs #tab #lf). i := 1. asciiNames do: [ :each | self class compile: each asString , ' ^ asciiField at: ', i asString. i := i + 1 ]. which at least does what I want given names to ASCI Codes. Now I have to admit I dislike this stuff with putting a string togehter and run compile: on this string. I'm sure there is a more elegant way. Would you mind to lend me a hand? Yes and because I think I will need much more code generation in the near future. Does you have nice Tutorial, Book whatever to do such kind of jobs in Smalltalk I've quite a lot of books about Smalltalk but none has this as theme... So it's really a bit hard to get into it.... Regards Friedrich -- Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
Hi Friederich, here's two simple optimizations: #(#nul #soh #stx #etx #eot #enq #ack #bel #bs #tab #lf) withIndexDo: [:each :index | self class compile: each asString , ' ^ asciiField at: ', index asString.]. Array withAll: #(1 2 3) is equivalent to #(1 2 3), and if you're not going to use the array again, you don't even need to assign it to a variable :) Instead of manually using an index, it is more elegant to use withIndexDo: Cheers, Bernat Romagosa.
AxiNat <tibabenfortlapalanca@gmail.com> writes:
Hi Friederich, here's two simple optimizations:
#(#nul #soh #stx #etx #eot #enq #ack #bel #bs #tab #lf) Â Â withIndexDo: Â [:each :index | Â Â Â self class compile: each asString , ' Â ^ asciiField at: ', index asString.].
Array withAll: #(1 2 3) is equivalent to #(1 2 3), and if you're not going to use the array again, you don't even need to assign it to a variable :) Well I do not want the compile part with String
Instead of manually using an index, it is more elegant to use withIndexDo:
Ok that is really nice to know Regards Friedrich -- Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
Hi Friedrich, Am 31.03.2011 um 18:09 schrieb Friedrich Dominicus:
I've spend the better time of the afternoon with trying metaprogramming with Smalltalk I finally have come up with:
asciiNames := Array withAll: #(#nul #soh #stx #etx #eot #enq #ack #bel #bs #tab #lf). i := 1. asciiNames do: [ :each | self class compile: each asString , ' ^ asciiField at: ', i asString. i := i + 1 ].
if you don't like string concatenation you may find this useful #(#nul #soh #stx #etx #eot #enq #ack #bel #bs #tab #lf) withIndexDo: [:each :index | self class compile: ('<1s><n><t>^ asciiField at: <2s>' expandMacrosWith: each with: index printString) classified: #(#accessing)]
which at least does what I want given names to ASCI Codes. Now I have to admit I dislike this stuff with putting a string togehter and run compile: on this string.
I'm sure there is a more elegant way. Would you mind to lend me a hand?
Yes and because I think I will need much more code generation in the near future. Does you have nice Tutorial, Book whatever to do such kind of jobs in Smalltalk I've quite a lot of books about Smalltalk but none has this as theme... So it's really a bit hard to get into it....
Well, I think you have the perfect source for learning right in front of you. The code snippet above didn't come from my mind. I just remembered that if you are on a class you can open the menu, open 'Refactor Class' and select Accessors to have pharo generate getters and setters for you. So I wrote "Accessors" (with the double quotes) in the workspace selected it and did a string seach (shortcurt E). From the choice given 'ORCmdAccessorClassRefactoring' seemed to be the most feasible. Then I investigated the methods found some other reference and so on (I leave this as an exercise). Finally I found a snippet which I copied and altered for your needs. This way I learned something about OmniBrowser, Refactoring-Engine and that there is a method expandMacrosWith: :) I think this is the way to go. Often it is hard if you first have to think about a problem that you can solve. But you have a problem so with the very good searching capabilities of pharo you can find such things easily. Hope this helps, Norbert
Norbert Hartl <norbert@hartl.name> writes:
Well, I think you have the perfect source for learning right in front of you. The code snippet above didn't come from my mind. I just remembered that if you are on a class you can open the menu, open 'Refactor Class' and select Accessors to have pharo generate getters and setters for you. So I wrote "Accessors" (with the double quotes) in the workspace selected it and did a string seach (shortcurt E). From the choice given 'ORCmdAccessorClassRefactoring' seemed to be the most feasible. Then I investigated the methods found some other reference and so on (I leave this as an exercise). Finally I found a snippet which I copied and altered for your needs. This way I learned something about OmniBrowser, Refactoring-Engine and that there is a method expandMacrosWith: :)
Well I'm old fashioned, I like to look into books and see somethign step-by-step. Unfortunatly the most Smalltalk books are lacking in that area (for my taste) Regards Friedrich -- Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
participants (5)
-
AxiNat -
Friedrich Dominicus -
Marcus Denker -
Norbert Hartl -
Panu Suominen