[squeak-dev] Re: Can i has underscores? :)

Igor Stasenko siguctua at gmail.com
Thu Apr 15 10:28:21 UTC 2010


On 15 April 2010 07:39, Andreas Raab <andreas.raab at gmx.de> wrote:
> On 4/14/2010 5:22 PM, Igor Stasenko wrote:
>>
>> Here the code, Stéphane.
>>
>> Please, let me know, if it meets your expectations.
>
> Ah! See *now* we're talking. This is useful because we can immediately put
> this to a real test along the lines of:
>
> Smalltalk allClasses do:[:cls|
>  cls selectorsAndMethodsDo:[:sel :method|
>    | source filtered node compiled |
>    source := (cls sourceCodeAt: sel) asString.
>    (source indexOf: $_) > 0 ifTrue:[
>      filtered := (UnderscoreFilter on: source readStream)
>        replacement: ':='; upToEnd.
>      source = filtered ifFalse:[
>        Transcript cr; show: cls name, '>>', sel.
>        node := cls compilerClass new compile: filtered
>          in: cls classified: nil notifying: nil ifFail: nil..
>        compiled := node generate: method trailer.
>        self assert: (method equivalentTo: compiled).
>      ].
>    ].
>  ].
> ] displayingProgress:[:cls| 'Verifying ', cls name].
>
> What this does is verifying that your underscore filter indeed replaces all
> the source code correctly. It also spits out where underscores are used and
> I was positively surprised that it seems as if there are precisely 11
> methods with underscore assignments left in Squeak 4.1.
>
> The other thing we can do with it is to wrap it into a more useful form
> where we 'auto-detect' whether to translate underscores and do so only if
> needed. Check out the attached code - it provides the fileIn facilities in a
> separate class so that we can properly modify and install variations by
> subclassing. Also note that the idea is that generally we detect the
> underscore usage by looking at the fileOut version (which is fast) but if
> not present we might look at the file contents, too (this is left as an
> exercise for the interested reader :-)
>
Yes, that is exactly what i have proposed - use clever approach when
reading files.
My proposal was more explicit - i.e. put something like: Me usingUnderscores. !
But yours also ok , except that some fileouts don't using the 'From
Squeak blabla' headers (see an attachment for instance).
If file contains a fileout version header, then we can make some
assumptions what to expect from its contents.

> BTW, I've also added a test for a fileIn translation that shows a case where
> your filter goes wrong - when having something like #(1 2 3 _ 4 5) you're
> replacing the underscore in the literal array with := even though it's
> equivalent to #'_'.
>

Interesting edge case :)
Btw its inconsistent in current image:
#( _ )
printed as
 #(#':=')

Preference were:  allow underscore assignments = true, allow
underscore selectors = false.

With allow underscore assignments = false, allow underscore selectors = false
it throws an error while parsing such literal:
 Illegal character (char code 95 16r5F) ->

With allow underscore assignments = false, allow underscore selectors = true
it prints
 #(#'_')

in older image (took 3.10.2), it printed as
#(#'_')

I think it should print same results irrespectively of what preference set.
And my pick is:  Illegal character (char code 95 16r5F)
IMO, we should disallow an ambiguous things in syntax.  And #( _ ) is ambiguous.

Another interesting thing, which i found is, that syntax allows an
arbitrary number of spaces between
# and (
so, even:

#  fooo
prints as #fooo

is this correct smalltalk syntax?

Here is updated version, which deals with array literals ( i hope ).

> Between UnderscoreFilter and FileInManager we're slowly getting there. The
> issues left are:
> * Dealing with is Monticello. If we can figure out how to extract a
> SystemVersion string from it we should be able to use the same basic
> approach.

> * Using the Unicode glyph. I'm not certain what the best way to deal with
> this is, but it'd be good if we could also support the 'real' left-arrow
> glyph and translate underscore to left-arrow instead of :=.

Well, first, we certaintly need a better default font support of
unicode characters.
Making it work only for left-arrow will be just another hack, which i
would prefer to not do at all.
Either we doing it good (unicode support), or not doing at all.

> * Typing the Unicode glyph. This could be done by a simple preference that
> maps underscore to left-arrow.
>
Yeah, this is trivial thing :)

> Cheers,
>  - Andreas


-- 
Best regards,
Igor Stasenko AKA sig.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Underscore-GoodBye.st
Type: application/octet-stream
Size: 5082 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20100415/d8f881ea/Underscore-GoodBye.obj


More information about the Squeak-dev mailing list