[squeak-dev] Extracting argument names from a block

Frank Shearar frank.shearar at gmail.com
Mon May 21 21:27:03 UTC 2012


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 -
>
>
>


More information about the Squeak-dev mailing list