[squeak-dev] Extracting argument names from a block

Frank Shearar frank.shearar at gmail.com
Tue May 22 09:28:41 UTC 2012


On 22 May 2012 00:40, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> Frank,
>
>    is this close enough?
>
> [:a :block :with :args|] decompile arguments collect: [:ea| ea key] #('a'
> 'block' 'with' 'args')
>
> Not symbols, but strings.

I need symbols, but that's trivial to do. Thanks for pointing out #key
- that's definitely more intention-revealing.

Why does VariableNode introduce #name? It's not publically settable,
and it looks like it's almost always true that name = key. "Almost"
because SyntaxMorph >> #printVariableNodeOn:indent: sets a
VariableNode's key to nil. Ah. VariableNode >> #isSelfPseudoVariable
has this: "^ key = 'self' or: [name = '{{self}}']". So the two are
MOSTLY equal, except for self, and except for whatever reason
SyntaxMorph has.

frank

> On Mon, May 21, 2012 at 2:27 PM, Frank Shearar <frank.shearar at gmail.com>
> wrote:
>>
>> On 21 May 2012 22:00, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> > On 21.05.2012, at 22:47, Frank Shearar wrote:
>> >
>> >> Without having to decompile a block, how may I find the names of a
>> >> block's arguments?
>> >>
>> >> In other words, given
>> >>
>> >>     [:a :b :c | "stuff"]
>> >>
>> >> I'd like to extract #(a b c).
>> >>
>> >> (Failing that, I'll have to live with myBlock decompile arguments
>> >> collect: [:a | a name asSymbol]).
>> >>
>> >> frank
>> >
>> > I don't know (I'm even surprise the decompiler knows) - but can you say
>> > a little bit more for what you would need that?
>>
>> Sure! I'm working on a miniKanren-like logic programming
>> language/framework. Typically in a miniKanren clone there's a macro
>> called "fresh" that introduces logic variables. For instance,
>>
>> (fresh [x y]
>>  (== [x y] [1 5]))
>>
>> introduces two logic variables called x and y, and then unifies [x y]
>> with [1 5] to give the substitution/most general unifier x -> 1, y ->
>> 5.
>>
>> So I thought I could do something like
>>
>> [:x :y | {x. y} unifyWith: #(1 5)] fresh
>>
>> where BlockClosure >> #fresh currently looks like this:
>>
>> fresh
>>        ^ self valueWithArguments: (self decompile arguments collect: [:a |
>> a
>> name asSymbol]).
>>
>> frank
>>
>> > - Bert -
>> >
>> >
>> >
>>
>
>
>
> --
> best,
> Eliot
>
>
>
>


More information about the Squeak-dev mailing list