grabbing value of a variabe by its name?

Joern Eyrich Joern.Eyrich at syngenio.de
Thu Jul 25 15:01:34 UTC 2002


I think what Ragnar wants is not the values *instead of* the names, but *both* of them - kind of like a Dictionary with its keys and values - but ... well ... without the Dictionary ;-)

he wants to put the names of variables into an object and then be able to ask it
1) for a list of the variable names
2) for a list of the corresponding values

Ragnar, did i get that right?

I think this is not easy to do cleanly.

for this
> fields _ SQLFields new: #(var1 var2 var3).
> execute 'insert into table1 (', fields asNames, ') values (',
>         fields asValues, ')'.
to work, SQLFields' methods would have to reach into the method execution contexts of their senders or access other objects' instance methods by name, as far as I can see.

I guess using a Dictionary would be the cleanest solution (that comes to my mind, anyway).

Joern 

Alan Kay wrote:
> 
> Ragnar --
> 
> I think the construct that is most like you are looking for would be
> to type the following into a workspace and execute them with a "cmd
> (or alt) d":
> 
> foo _ 'hello'.
> bar _ 'world'.
> baz _ { foo. bar}.
> 
> If you then type
> 
> baz
> 
> and execute this with a "print it" -- a "cmd (or alt) d", then you will see
> 
> #('hello' 'world')
> 
> But the suggestion below will also work. The construct:
> 
> baz _ Array with: foo with: bar
> 
> will put the very same Array structure into baz, and you can see this
> by executing:
> 
> baz
> 
> with a "cmd (or alt) d"
> 
> Cheers,
> 
> Alan
> 
> -----
> 
> At 3:28 PM +0200 7/25/02, Ragnar Hojland Espinosa wrote:
> >On Thu, Jul 25, 2002 at 07:22:03AM -0500, Martin McClure wrote:
> >>  At 1:42 PM +0200 7/25/02, Ragnar Hojland Espinosa wrote:
> >>  >foo _ 'hello'.
> >>  >bar _ 'world!'.
> >>  >baz _ #(foo bar).
> >>  >
> >>  >I can get the name of the var by a (baz at: 1), but how do i get its value?
> >>
> >>  The construct "#(foo bar)" specifies a literal Array that contains
> >>  two literally-specified Symbols, #foo and #bar. It does not reference
> >>  any variables.
> >>
> >>  One way to get what you're looking for is
> >>
> >>  baz _ Array with: foo with: bar.
> >
> >Uhh, i dont see how.. please elaborate a bit.  The following would work, but
> >it saves nothing.
> >
> >baz _ at: 'foo' put: foo.
> >baz _ at: 'bar' put: bar.
> >
> >
> >--
> >Ragnar Hojland - Project Manager
> >Linalco "Especialistas Linux y en Software Libre"
> >Tel: +34-91-5970074 Fax: +34-91-5970083
> 
> --



More information about the Squeak-dev mailing list