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 |
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? - Bert - |
On 21 May 2012 22:00, Bert Freudenberg <[hidden email]> 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 - > > > |
Frank,
is this close enough? [:a :block :with :args|] decompile arguments collect: [:ea| ea key] #('a' 'block' 'with' 'args') Not symbols, but strings.
On Mon, May 21, 2012 at 2:27 PM, Frank Shearar <[hidden email]> wrote:
best, Eliot |
Hi Eliot -
It's good I looked at this, as it seems to have some bit rot (students in the repo ;-). But check it out at... I think it will be obvious. Ciao PS: Nice to be in contact Needs a bit of work before it's smooth on iPad etc |
In reply to this post by Eliot Miranda-2
On 22 May 2012 00:40, Eliot Miranda <[hidden email]> 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 <[hidden email]> > wrote: >> >> On 21 May 2012 22:00, Bert Freudenberg <[hidden email]> 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 > > > > |
Free forum by Nabble | Edit this page |