[squeak-dev] [Question] nil, true, false in array literals

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Question] nil, true, false in array literals

Claus Kick
Gerardo Richarte wrote:

>
>> you would say:
>>
>>   #(1 2.0 true false 'string' #foo #bar #baz)
>>
>> in which case you might even be able to get rid of {} ...
>
>
> if my opinion counts for anything, this is what I would like most.

I second that, although my opinion does definitely not count.
{} to me is Algol, not Smalltalk, hence the enemy :D

(Although I unfortunately earn my keep with the {} languages these days)


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: [Question] nil, true, false in array literals

Paolo Bonzini-2
In reply to this post by Vassili Bykov-2

> FWIW, here is the Newspeak angle:
>
> The traditional Smalltalk syntax of #(...) is not valid in any form.

And FWIW, in GNU Smalltalk even though #(...) is obviously valid, I
removed the #(abc) shortcut for symbols.  The only words without sharps
are exactly true, false, nil.

Paolo


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Question] nil, true, false in array literals

Stéphane Rollandin

> And FWIW, in GNU Smalltalk even though #(...) is obviously valid, I
> removed the #(abc) shortcut for symbols.  The only words without sharps
> are exactly true, false, nil.
>
> Paolo

OTOH the current behavior in Squeak allows fun things, such as having
lisp code cleanly stored as an array of symbol:

prog := #(funcall (lambda (x) (sqrt x)) 5) asCons

(more here: http://www.zogotounga.net/comp/squeak/lispkit.htm)


Stef




Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: [Question] nil, true, false in array literals

Paolo Bonzini-2
Stéphane Rollandin wrote:
>
>> And FWIW, in GNU Smalltalk even though #(...) is obviously valid, I
>> removed the #(abc) shortcut for symbols.  The only words without sharps
>> are exactly true, false, nil.
>
> OTOH the current behavior in Squeak allows fun things, such as having
> lisp code cleanly stored as an array of symbol:
>
> prog := #(funcall (lambda (x) (sqrt x)) 5) asCons

Yeah, it's a lossy change.  But I'm more for consistency.

Paolo

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Question] nil, true, false in array literals

Claus Kick
In reply to this post by Stéphane Rollandin
Stéphane Rollandin wrote:

>
>> And FWIW, in GNU Smalltalk even though #(...) is obviously valid, I
>> removed the #(abc) shortcut for symbols.  The only words without sharps
>> are exactly true, false, nil.
>>
>> Paolo
>
>
> OTOH the current behavior in Squeak allows fun things, such as having
> lisp code cleanly stored as an array of symbol:
>
> prog := #(funcall (lambda (x) (sqrt x)) 5) asCons

and then you do something like this
(anArray at:1) perform: ((anArray at:2) at:1) ? :)

Aside:
In my book, the ability to having objects perform symbols is one of the
drawbacks of Smalltalk, if done in actual production code.

At my former job, there was stuff like

doSomething: anArgument

(anArgument kindOf: aClass) ifTrue:[sel := aClass, '_', 'performer'].
anArgument perform: (sel asSymbol).

Have fun debugging this ...

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Question] nil, true, false in array literals

Stéphane Rollandin

>> prog := #(funcall (lambda (x) (sqrt x)) 5) asCons
>
> and then you do something like this
> (anArray at:1) perform: ((anArray at:2) at:1) ? :)

no, the #asCons part convert the array into a cons cell.

the actual usage is in methods like ULisp class>>#amb where Lisp code
can be written directly in Smalltalk:

==========================

amb

        ^#(in-library amb

(define amb-fail `*)

(define initialize-amb-fail
   (lambda ()
     (set! amb-fail
       (lambda ()
         (error 'amb tree exhausted')))))

(initialize-amb-fail)

(define-macro amb
   (lambda #'alts...'
     `(let ((#'+prev-amb-fail' amb-fail))
        (call/cc
         (lambda (#'+sk')
           ,@(map (lambda (alt)
                    `(call/cc
                      (lambda (#'+fk')
                        (set! amb-fail
                          (lambda ()
                            (set! amb-fail #'+prev-amb-fail')
                            (#'+fk' `fail)))
                        (#'+sk' ,alt))))
                        #'alts...')
           (#'+prev-amb-fail'))))))

(define assert
   (lambda (pred)
     (if (not pred) (amb))))

(define-macro bag-of
   (lambda (e)
     `(let ((#'+prev-amb-fail' amb-fail)
            (#'+results' `()))
        (if (call/cc
             (lambda (#'+k')
               (set! amb-fail (lambda () (#'+k' false)))
               (let ((#'+v' ,e))
                 (set! #'+results' (cons #'+v' #'+results'))
                 (#'+k' true))))
            (amb-fail))
        (set! amb-fail #'+prev-amb-fail')
        (reverse! #'+results'))))
        )

===============================================


... so this goes a little beyond the fast dirty hack thing :)


there is much more in LispKit, here is the link again:
http://www.zogotounga.net/comp/squeak/lispkit.htm


Stef



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: [Question] nil, true, false in array literals

Claus Kick
Stéphane Rollandin wrote:
>
>>> prog := #(funcall (lambda (x) (sqrt x)) 5) asCons
>>
>>
>> and then you do something like this
>> (anArray at:1) perform: ((anArray at:2) at:1) ? :)
>
> no, the #asCons part convert the array into a cons cell.

Ok?

> the actual usage is in methods like ULisp class>>#amb where Lisp code
> can be written directly in Smalltalk:
>

*snip code*

Ah, ok, this makes sense indeed!

>
>
> ... so this goes a little beyond the fast dirty hack thing :)

Ok, point taken, this goes definitely beyond a fast and dirty hack :)

12