Re: [Pharo-users] Methods & Classes using the command line.

2017-04-13 Thread Peter Uhnak
This should be similar to having the code in playground and executing it at 
once. I guess it's more forgiving.

What I sometimes do to work around it is to store the created class into 
variable, or use symbol and asClass cast

e.g.

cls := Object subclass: #TestClass.
cls compile:'meth'.

or

Object subclass: #TestClass.
#TestClass asClass compile:'meth'.

Peter


On Thu, Apr 13, 2017 at 07:39:24PM +0200, Guillermo Polito wrote:
> Hi,
> 
> On Thu, Apr 13, 2017 at 6:57 PM, nacho <0800na...@gmail.com> wrote:
> 
> > Hi pharoers,
> >
> > If I do the following in a minimal Pharo image, using the command line:
> >
> > ./Pharo --headless Pharo.image eval "Object subclass: #TestClass
> > instanceVariableNames: 'one' classVariableNames: '' package: 'IS-Test'."
> >
> > I get the class created. However, if I try to pass the following argument
> > to
> > eval:
> >
> > "Object subclass: #TestClass instanceVariableNames: 'one'
> > classVariableNames: '' package: 'IS-Test'. TestClass compile:'one ^one'
> > classified: 'accessor'."
> 
> 
> > I get an UndefinedObject>>DoIt (TestClass is Undeclared).
> >
> 
> The problem is that the entire code is compiled at the same time. So, when
> the expression is compiled, the class TestClass does not exist yet. And
> what you see is a compiler warning.
> 
> However, as soon as the class is created, the class is available to the
> already compiled code and should work.
> 
> Moreover: if the TestClass was not created, you would have got an exception
> "nil does not understand compile:classified:" ;)
> 
> 
> >
> > At first I thought it could be that it takes sometime to compile the class,
> > so added some delay:
> >
> > "Object subclass: #TestClass instanceVariableNames: 'one'
> > classVariableNames: '' package: 'IS-Test'. (Delay forSeconds: 5) wait.
> > TestClass compile:'one ^one' classified: 'accessor'."
> >
> > But again: UndefinedObject>>DoIt (TestClass is Undeclared).
> >
> > I even tried to do:
> >
> > "Object subclass: #TestClass instanceVariableNames: 'one'
> > classVariableNames: '' package: 'IS-Test'. Smalltalk saveAndQuit."
> >
> > and after that add only a method by passing:
> >
> > "TestClass compile:'one ^one' classified: 'accessor'. Smalltalk
> > saveAndQuit."
> >
> 
> This is strange because, the class is created and you're saving the
> image... If I try:
> 
> ./pharo Pharo.image eval "Object subclass: #TestClass
> instanceVariableNames: 'one'
> classVariableNames: '' package: 'IS-Test'. TestClass compile:'one ^one'
> classified: 'accessor'. TestClass"
> 
> (note that I just aded *TestClass * at the end) I get the following output:
> 
> =>
> UndefinedObject>>DoIt (TestClass is Undeclared)
> 
> UndefinedObject>>DoIt (TestClass is Undeclared)
> TestClass
> 
> That is: two compiler warnings. + the class that is printed at the end.
> 
> So it's working well on my end, delta the confusing warnings.
> 
> 
> > But again: UndefinedObject>>DoIt (TestClass is Undeclared)
> >
> > How do I add a method to a class using the command line?
> > Thanks in advance
> > Nacho
> >
> >
> >
> > -
> > Nacho
> > Smalltalker apprentice.
> > Buenos Aires, Argentina.
> > --
> > View this message in context: http://forum.world.st/Methods-
> > Classes-using-the-command-line-tp4941977.html
> > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
> >
> >



Re: [Pharo-users] Methods & Classes using the command line.

2017-04-13 Thread Guillermo Polito
Hi,

On Thu, Apr 13, 2017 at 6:57 PM, nacho <0800na...@gmail.com> wrote:

> Hi pharoers,
>
> If I do the following in a minimal Pharo image, using the command line:
>
> ./Pharo --headless Pharo.image eval "Object subclass: #TestClass
> instanceVariableNames: 'one' classVariableNames: '' package: 'IS-Test'."
>
> I get the class created. However, if I try to pass the following argument
> to
> eval:
>
> "Object subclass: #TestClass instanceVariableNames: 'one'
> classVariableNames: '' package: 'IS-Test'. TestClass compile:'one ^one'
> classified: 'accessor'."


> I get an UndefinedObject>>DoIt (TestClass is Undeclared).
>

The problem is that the entire code is compiled at the same time. So, when
the expression is compiled, the class TestClass does not exist yet. And
what you see is a compiler warning.

However, as soon as the class is created, the class is available to the
already compiled code and should work.

Moreover: if the TestClass was not created, you would have got an exception
"nil does not understand compile:classified:" ;)


>
> At first I thought it could be that it takes sometime to compile the class,
> so added some delay:
>
> "Object subclass: #TestClass instanceVariableNames: 'one'
> classVariableNames: '' package: 'IS-Test'. (Delay forSeconds: 5) wait.
> TestClass compile:'one ^one' classified: 'accessor'."
>
> But again: UndefinedObject>>DoIt (TestClass is Undeclared).
>
> I even tried to do:
>
> "Object subclass: #TestClass instanceVariableNames: 'one'
> classVariableNames: '' package: 'IS-Test'. Smalltalk saveAndQuit."
>
> and after that add only a method by passing:
>
> "TestClass compile:'one ^one' classified: 'accessor'. Smalltalk
> saveAndQuit."
>

This is strange because, the class is created and you're saving the
image... If I try:

./pharo Pharo.image eval "Object subclass: #TestClass
instanceVariableNames: 'one'
classVariableNames: '' package: 'IS-Test'. TestClass compile:'one ^one'
classified: 'accessor'. TestClass"

(note that I just aded *TestClass * at the end) I get the following output:

=>
UndefinedObject>>DoIt (TestClass is Undeclared)

UndefinedObject>>DoIt (TestClass is Undeclared)
TestClass

That is: two compiler warnings. + the class that is printed at the end.

So it's working well on my end, delta the confusing warnings.


> But again: UndefinedObject>>DoIt (TestClass is Undeclared)
>
> How do I add a method to a class using the command line?
> Thanks in advance
> Nacho
>
>
>
> -
> Nacho
> Smalltalker apprentice.
> Buenos Aires, Argentina.
> --
> View this message in context: http://forum.world.st/Methods-
> Classes-using-the-command-line-tp4941977.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


[Pharo-users] Methods & Classes using the command line.

2017-04-13 Thread nacho
Hi pharoers,

If I do the following in a minimal Pharo image, using the command line:

./Pharo --headless Pharo.image eval "Object subclass: #TestClass
instanceVariableNames: 'one' classVariableNames: '' package: 'IS-Test'."

I get the class created. However, if I try to pass the following argument to
eval:

"Object subclass: #TestClass instanceVariableNames: 'one'
classVariableNames: '' package: 'IS-Test'. TestClass compile:'one ^one'
classified: 'accessor'."

I get an UndefinedObject>>DoIt (TestClass is Undeclared).

At first I thought it could be that it takes sometime to compile the class,
so added some delay:

"Object subclass: #TestClass instanceVariableNames: 'one'
classVariableNames: '' package: 'IS-Test'. (Delay forSeconds: 5) wait.
TestClass compile:'one ^one' classified: 'accessor'."

But again: UndefinedObject>>DoIt (TestClass is Undeclared).

I even tried to do:

"Object subclass: #TestClass instanceVariableNames: 'one'
classVariableNames: '' package: 'IS-Test'. Smalltalk saveAndQuit."

and after that add only a method by passing:

"TestClass compile:'one ^one' classified: 'accessor'. Smalltalk
saveAndQuit."

But again: UndefinedObject>>DoIt (TestClass is Undeclared) 

How do I add a method to a class using the command line? 
Thanks in advance
Nacho



-
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: 
http://forum.world.st/Methods-Classes-using-the-command-line-tp4941977.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.