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. -- Panu |
On Tue, Mar 29, 2011 at 09:08:33AM +0300, 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. FileDirectory class>>slash |
In reply to this post by Panu Suominen-3
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 <[hidden email]>:
> > 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.
|
In reply to this post by FDominicus
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 |
In reply to this post by Bernat Romagosa
AxiNat <[hidden email]> 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 |
In reply to this post by Bernat Romagosa
On Apr 1, 2011, at 10:10 AM, Friedrich Dominicus wrote: > AxiNat <[hidden email]> 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 So you could override #doesNotUnderstand: and there check if someone sends a message #etx (and the others) and then return the value. (you then want to store the value in a dictionary keyed by the the message name). doesNotUnderstand: aMessage | dict | dict := (#(nul soh stx etx eot enq ack bel bs tab lf) collectWithIndex: [:elem :index | elem -> index]) asDictionary. ^dict at: aMessage selector ifAbsent: [^super doesNotUnderstand: aMessage]. But of course doesNotUnderstand: is always a bit magic... and should be used with care. As for strings stiched together: yes, *horrible*. And we plan to move on to something better soon. In general, I like the idea to have a reflective model of the structure of methods... When talking about code, we should not use string... the Quasi-Quoting from Helvetia is far better than string manipulation: http://scg.unibe.ch/research/helvetia/examples#168249369 That combined with a good AST should make these things much easier. Marcus -- Marcus Denker -- http://www.marcusdenker.de INRIA Lille -- Nord Europe. Team RMoD. |
In reply to this post by NorbertHartl
Norbert Hartl <[hidden email]> 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: :) 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 |
Free forum by Nabble | Edit this page |