Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
238 posts
|
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.
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
2446 posts
|
Hi,
On Thu, Apr 13, 2017 at 6:57 PM, nacho <[hidden email]> wrote: Hi pharoers,
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:" ;)
... [show rest of quote] 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.
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
2019 posts
|
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 <[hidden email]> 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. > > > > ... [show rest of quote] |
Free forum by Nabble | Edit this page |