metaprogramming in smalltalk

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

metaprogramming in smalltalk

vittly
Hi! Please could you help me understand smalltalk capabilities in metaprogramming? Q: could I construct arbitrary message by program? Create keywords from strings and than build sequence of them to make a message. Mm? Or may be store keywords in variables and then pass variables withing messages extracting stored keywords?
Am I dreamer?)
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

Francisco Garau
Mmhm - sounds like a home assignment to me...

Go to www.pharo.org download it and have a look in the browser.

- Francisco


On 29 Apr 2012, at 09:25, vittly <[hidden email]> wrote:

> Hi! Please could you help me understand smalltalk capabilities in
> metaprogramming? Q: could I construct arbitrary message by program? Create
> keywords from strings and than build sequence of them to make a message. Mm?
> Or may be store keywords in variables and then pass variables withing
> messages extracting stored keywords?
> Am I dreamer?)
>
>
> --
> View this message in context: http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
> Sent from the ESUG mailing list archive at Nabble.com.
>
> _______________________________________________
> Esug-list mailing list
> [hidden email]
> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

Richard Sargent (again)
In reply to this post by vittly
Smalltalk is fully reflective, designed to be so right from the start.

So the answer to your question is "Yes".
 

-----Original Message-----
From: vittly [mailto:[hidden email]]
Sent: April-29-12 10:25 AM
To: [hidden email]
Subject: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

Georg Heeg
In reply to this post by vittly
Please try to understand the following code:

| a b c |

a := 3.
b := 4.
c := '+'.
^a perform: c asSymbol with: b

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Wallstraße 22, 06366 Köthen
Tel. +49-3496-214328, Fax +49-3496-214712


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von vittly
Gesendet: Sonntag, 29. April 2012 10:25
An: [hidden email]
Betreff: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

vittly
Mmm thnx for replie! I'll run this code and experemt with it

2012/4/29 Georg Heeg [via Smalltalk] <[hidden email]>
Please try to understand the following code:

| a b c |

a := 3.
b := 4.
c := '+'.
^a perform: c asSymbol with: b

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Wallstraße 22, 06366 Köthen
Tel. +49-3496-214328, Fax +49-3496-214712


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von vittly
Gesendet: Sonntag, 29. April 2012 10:25
An: [hidden email]
Betreff: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4596217.html
To unsubscribe from metaprogramming in smalltalk, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

vittly
Ok. perform: is working for arithmetic but what about perform: itself?
| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:'.
wi := 'with:'.
args := Array new: 3.
args 
at: 1 put: plu asSymbol;
at: 2 put: wi asSymbol;
at: 3 put: y.
x perform: perf asSymbol withArguments: args.

This code tells me that there is wrong number of arguments in permforn:
How can I fix it?


2012/4/29 vittly <[hidden email]>
Mmm thnx for replie! I'll run this code and experemt with it

2012/4/29 Georg Heeg [via Smalltalk] <[hidden email]>
Please try to understand the following code:

| a b c |

a := 3.
b := 4.
c := '+'.
^a perform: c asSymbol with: b

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Wallstraße 22, 06366 Köthen
Tel. +49-3496-214328, Fax +49-3496-214712


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von vittly
Gesendet: Sonntag, 29. April 2012 10:25
An: [hidden email]
Betreff: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4596217.html
To unsubscribe from metaprogramming in smalltalk, click here.
NAML



View this message in context: Re: metaprogramming in smalltalk

Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

Joseph Pelrine
In reply to this post by Georg Heeg
Nice! Almost as elegant as Ward's legendary

Symbol>>value: anObject
^anObject perform: self

On 29.04.12 13:49, Georg Heeg wrote:

> Please try to understand the following code:
>
> | a b c |
>
> a := 3.
> b := 4.
> c := '+'.
> ^a perform: c asSymbol with: b
>
> Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
> Wallstraße 22, 06366 Köthen
> Tel. +49-3496-214328, Fax +49-3496-214712
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von vittly
> Gesendet: Sonntag, 29. April 2012 10:25
> An: [hidden email]
> Betreff: [Esug-list] metaprogramming in smalltalk
>
> Hi! Please could you help me understand smalltalk capabilities in
> metaprogramming? Q: could I construct arbitrary message by program? Create
> keywords from strings and than build sequence of them to make a message. Mm?
> Or may be store keywords in variables and then pass variables withing
> messages extracting stored keywords?
> Am I dreamer?)
>
>
> --
> View this message in context:
> http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
> Sent from the ESUG mailing list archive at Nabble.com.
>
> _______________________________________________
> Esug-list mailing list
> [hidden email]
> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>
>
> _______________________________________________
> Esug-list mailing list
> [hidden email]
> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>

--
Joseph Pelrine [ | ]
MetaProg GmbH
Email: [hidden email]
Web:   http://www.metaprog.com

As soon as you introduce people, things become complex.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

vittly
In reply to this post by vittly
Nice! Almost as elegant as Ward's legendary 
Symbol>>value: anObject 
^anObject perform: self 
Mickey!) I don't understand how does it help me.

The method is called #perform:with: and it takes two arguments.  
Yes. But what if I need to emulate "x perform: y with: z" - there is three arguments

How can I do this using perform?

Yes, there is Behavior class that compile everything so non can help this method is good. But what about perform? Message class also require selector and what is selector for keyword messages?

2012/4/29 Jean-François LEFEVRE <[hidden email]>
You probably want to do something like this :


| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:withArguments:'.
args := Array new: 1.
args at: 1 put: y.
x perform: perf asSymbol withArguments: args

You should look the class Message too.
(and all other classes and methods like Behavior, Class, Metaclass, Method and Object)

Jean-François



2012/4/29 Vitaly Kosenko <[hidden email]>
Ok. perform: is working for arithmetic but what about perform: itself?
| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:'.
wi := 'with:'.
args := Array new: 3.
args 
at: 1 put: plu asSymbol;
at: 2 put: wi asSymbol;
at: 3 put: y.
x perform: perf asSymbol withArguments: args.

This code tells me that there is wrong number of arguments in permforn:
How can I fix it?


2012/4/29 vittly <[hidden email]>
Mmm thnx for replie! I'll run this code and experemt with it

2012/4/29 Georg Heeg [via Smalltalk] <[hidden email]>
Please try to understand the following code:

| a b c |

a := 3.
b := 4.
c := '+'.
^a perform: c asSymbol with: b

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Wallstraße 22, 06366 Köthen
Tel. <a href="tel:%2B49-3496-214328" value="+493496214328" target="_blank">+49-3496-214328, Fax <a href="tel:%2B49-3496-214712" value="+493496214712" target="_blank">+49-3496-214712


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von vittly
Gesendet: Sonntag, 29. April 2012 10:25
An: [hidden email]
Betreff: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4596217.html
To unsubscribe from metaprogramming in smalltalk, click here.
NAML



View this message in context: Re: metaprogramming in smalltalk

Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org




_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

Guillermo Polito
Hi Vitaly!

try to think it like this: #perform:with: is a reflective operation to send messags to an object.  Thus, if you are trying to send an object a message like:

object perform: someSelector with: someArgument.

- The receiver is object
- the selector of the message is #perform:with:
- the arguments of #perform:with: are someSelector and someArgument.

Then, what you have to do is

object
   perform: #perform:with:
   withArguments: { someSelector . someArgument }

Because #perform: and #with: are not two different messages, they are two keywords of the same selector, in the same message.  Then, you have to treat them together.

Cheers,
Guille

2012/4/29 Vitaly Kosenko <[hidden email]>
Nice! Almost as elegant as Ward's legendary 
Symbol>>value: anObject 
^anObject perform: self 
Mickey!) I don't understand how does it help me.

The method is called #perform:with: and it takes two arguments.  
Yes. But what if I need to emulate "x perform: y with: z" - there is three arguments

How can I do this using perform?

Yes, there is Behavior class that compile everything so non can help this method is good. But what about perform? Message class also require selector and what is selector for keyword messages?

2012/4/29 Jean-François LEFEVRE <[hidden email]>
You probably want to do something like this :


| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:withArguments:'.
args := Array new: 1.
args at: 1 put: y.
x perform: perf asSymbol withArguments: args

You should look the class Message too.
(and all other classes and methods like Behavior, Class, Metaclass, Method and Object)

Jean-François



2012/4/29 Vitaly Kosenko <[hidden email]>
Ok. perform: is working for arithmetic but what about perform: itself?
| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:'.
wi := 'with:'.
args := Array new: 3.
args 
at: 1 put: plu asSymbol;
at: 2 put: wi asSymbol;
at: 3 put: y.
x perform: perf asSymbol withArguments: args.

This code tells me that there is wrong number of arguments in permforn:
How can I fix it?


2012/4/29 vittly <[hidden email]>
Mmm thnx for replie! I'll run this code and experemt with it

2012/4/29 Georg Heeg [via Smalltalk] <[hidden email]>
Please try to understand the following code:

| a b c |

a := 3.
b := 4.
c := '+'.
^a perform: c asSymbol with: b

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Wallstraße 22, 06366 Köthen
Tel. <a href="tel:%2B49-3496-214328" value="+493496214328" target="_blank">+49-3496-214328, Fax <a href="tel:%2B49-3496-214712" value="+493496214712" target="_blank">+49-3496-214712


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von vittly
Gesendet: Sonntag, 29. April 2012 10:25
An: [hidden email]
Betreff: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4596217.html
To unsubscribe from metaprogramming in smalltalk, click here.
NAML



View this message in context: Re: metaprogramming in smalltalk

Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org




_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

vittly
| x y plu perf wi sel args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:'.
wi := 'with:'.
sel := perf,wi.
args := Array new: 2.
args
at: 1 put: plu asSymbol;
at: 2 put: y.
x perform: sel asSymbol withArguments: args.

It works! Great! Thanks a lot. About Pharo examples book: I have red some chapters but the real understanding comes only in prectice)

2012/4/30 Guillermo Polito <[hidden email]>
Hi Vitaly!

try to think it like this: #perform:with: is a reflective operation to send messags to an object.  Thus, if you are trying to send an object a message like:

object perform: someSelector with: someArgument.

- The receiver is object
- the selector of the message is #perform:with:
- the arguments of #perform:with: are someSelector and someArgument.

Then, what you have to do is

object
   perform: #perform:with:
   withArguments: { someSelector . someArgument }

Because #perform: and #with: are not two different messages, they are two keywords of the same selector, in the same message.  Then, you have to treat them together.

Cheers,
Guille


2012/4/29 Vitaly Kosenko <[hidden email]>
Nice! Almost as elegant as Ward's legendary 
Symbol>>value: anObject 
^anObject perform: self 
Mickey!) I don't understand how does it help me.

The method is called #perform:with: and it takes two arguments.  
Yes. But what if I need to emulate "x perform: y with: z" - there is three arguments

How can I do this using perform?

Yes, there is Behavior class that compile everything so non can help this method is good. But what about perform? Message class also require selector and what is selector for keyword messages?

2012/4/29 Jean-François LEFEVRE <[hidden email]>
You probably want to do something like this :


| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:withArguments:'.
args := Array new: 1.
args at: 1 put: y.
x perform: perf asSymbol withArguments: args

You should look the class Message too.
(and all other classes and methods like Behavior, Class, Metaclass, Method and Object)

Jean-François



2012/4/29 Vitaly Kosenko <[hidden email]>
Ok. perform: is working for arithmetic but what about perform: itself?
| x y plu perf wi args | 
x := 3.
y := 4. 
plu := '+'.
perf := 'perform:'.
wi := 'with:'.
args := Array new: 3.
args 
at: 1 put: plu asSymbol;
at: 2 put: wi asSymbol;
at: 3 put: y.
x perform: perf asSymbol withArguments: args.

This code tells me that there is wrong number of arguments in permforn:
How can I fix it?


2012/4/29 vittly <[hidden email]>
Mmm thnx for replie! I'll run this code and experemt with it

2012/4/29 Georg Heeg [via Smalltalk] <[hidden email]>
Please try to understand the following code:

| a b c |

a := 3.
b := 4.
c := '+'.
^a perform: c asSymbol with: b

Georg Heeg eK, Dortmund und Köthen, HR Dortmund A 12812
Wallstraße 22, 06366 Köthen
Tel. <a href="tel:%2B49-3496-214328" value="+493496214328" target="_blank">+49-3496-214328, Fax <a href="tel:%2B49-3496-214712" value="+493496214712" target="_blank">+49-3496-214712


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von vittly
Gesendet: Sonntag, 29. April 2012 10:25
An: [hidden email]
Betreff: [Esug-list] metaprogramming in smalltalk

Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4596217.html
To unsubscribe from metaprogramming in smalltalk, click here.
NAML



View this message in context: Re: metaprogramming in smalltalk

Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org




_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org




_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: metaprogramming in smalltalk

laurent laffont
In reply to this post by vittly
Hi,


Cheers,

Laurent

On Sun, Apr 29, 2012 at 10:25 AM, vittly <[hidden email]> wrote:
Hi! Please could you help me understand smalltalk capabilities in
metaprogramming? Q: could I construct arbitrary message by program? Create
keywords from strings and than build sequence of them to make a message. Mm?
Or may be store keywords in variables and then pass variables withing
messages extracting stored keywords?
Am I dreamer?)


--
View this message in context: http://forum.world.st/metaprogramming-in-smalltalk-tp4595928p4595928.html
Sent from the ESUG mailing list archive at Nabble.com.

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org