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

Reply via email to