Hi,
is it possible to accept a method without creating instance variable? E.g. ~~~~~~~~~~~~~~~~~~~~~~~~~~ Object subclass: #MyObject slots: { } classVariables: { } category: 'Category' ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ MyObject>>addValue: aValue container add: aValue ~~~~~~~~~~~~~~~~~~~~~~~~~~ Now normally when I would try to compile the method I would get the "Unknown variable 'container'" warning that will force me to either create temporary or instance variable; I would like to somehow ignore that, because the method will actually never get called. My objective is use this method as a template for code generation, so I would then take this method, apply some code transformation and compile it into different object. Of course I could do ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MyObject>>addValueTemplate ^ 'MyObject>>addValue: aValue container add: aValue' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ But then I would lose code highlighting, which is quite error-prone for more complex snippets. If you have a better approach, I am all ears. :) Thanks, Peter |
On Tue, Jun 28, 2016 at 5:55 PM, Peter Uhnak <[hidden email]> wrote:
> Hi, > > is it possible to accept a method without creating instance variable? > > E.g. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > Object subclass: #MyObject > slots: { } > classVariables: { } > category: 'Category' > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > MyObject>>addValue: aValue > container add: aValue > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Now normally when I would try to compile the method I would get the "Unknown variable 'container'" warning that will force me to either create temporary or instance variable; I would like to somehow ignore that, because the method will actually never get called. > > My objective is use this method as a template for code generation, so I would then take this method, apply some code transformation and compile it into different object. > > Of course I could do > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > MyObject>>addValueTemplate > ^ 'MyObject>>addValue: aValue > container add: aValue' > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > But then I would lose code highlighting, which is quite error-prone for more complex snippets. > > If you have a better approach, I am all ears. :) > > Thanks, > Peter If you are only templating the method and not the whole class, why not add it as an instance variable MyObject? Or if MyObject is a real domain object with a few template methods, maybe put the templates on the class side and add a dummy class-instance-variable there. cheers -ben |
Yeah I guess that's not such a bad idea, to have a TemplateClass that would contain just the template methods, so I don't need to worry about conflicting instance variables. Peter On Tue, Jun 28, 2016 at 2:08 PM, Ben Coman <[hidden email]> wrote:
|
Still, I think it would be nice to be able to save a method even when it does not compile. On Tue, Jun 28, 2016 at 2:52 PM, Peter Uhnák <[hidden email]> wrote:
|
On 28/06/2016 15:03, Nicolas Passerini wrote:
> Still, I think it would be nice to be able to save a method even when it > does not compile. > I think Marcus added the possibility to do that in Pharo 6 as a Setting. -- Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France signature.asc (817 bytes) Download Attachment |
In reply to this post by Nicolas Passerini
Ding dong Marcus! Le 28 juin 2016 15:04, "Nicolas Passerini" <[hidden email]> a écrit :
|
In reply to this post by Nicolas Passerini
Le 28/06/2016 15:03, Nicolas Passerini a écrit :
> Still, I think it would be nice to be able to save a method even when it > does not compile. I believe it would be better to be able to manipulate, inspect and edit properly virtual methods (MCMethodDefinition, RB-created methods) given that saving a method even if it does not compile is already possible, even if not made available in the GUI. Thierry > On Tue, Jun 28, 2016 at 2:52 PM, Peter Uhnák <[hidden email] > <mailto:[hidden email]>> wrote: > > Yeah I guess that's not such a bad idea, to have a TemplateClass > that would contain just the template methods, so I don't need to > worry about conflicting instance variables. > > Peter > > On Tue, Jun 28, 2016 at 2:08 PM, Ben Coman <[hidden email] > <mailto:[hidden email]>> wrote: > > On Tue, Jun 28, 2016 at 5:55 PM, Peter Uhnak <[hidden email] > <mailto:[hidden email]>> wrote: > > Hi, > > > > is it possible to accept a method without creating instance > variable? > > > > E.g. > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Object subclass: #MyObject > > slots: { } > > classVariables: { } > > category: 'Category' > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > MyObject>>addValue: aValue > > container add: aValue > > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > Now normally when I would try to compile the method I would > get the "Unknown variable 'container'" warning that will force > me to either create temporary or instance variable; I would like > to somehow ignore that, because the method will actually never > get called. > > > > My objective is use this method as a template for code > generation, so I would then take this method, apply some code > transformation and compile it into different object. > > > > Of course I could do > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > MyObject>>addValueTemplate > > ^ 'MyObject>>addValue: aValue > > container add: aValue' > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > But then I would lose code highlighting, which is quite > error-prone for more complex snippets. > > > > If you have a better approach, I am all ears. :) > > > > Thanks, > > Peter > > If you are only templating the method and not the whole class, > why not > add it as an instance variable MyObject? > Or if MyObject is a real domain object with a few template methods, > maybe put the templates on the class side and add a dummy > class-instance-variable there. > > cheers -ben > > > |
In reply to this post by Guillermo Polito
… is on Holidays… with the option #optionParseErrors you can compile code with syntax errors: method := Smalltalk compiler class: UndefinedObject; options: #(+ optionParseErrors); compile: 'errorMethod ^1+'. method valueWithReceiver: nil arguments: #() This is really compiled to raise a syntax error at runtime. see OCASTTranslator>>#visitParseErrorNode: anErrorNode methodBuilder pushLiteralVariable: #error -> anErrorNode asSyntaxErrorNotification; send: #signal. with RBParseErrorNode>>#asSyntaxErrorNotification ^SyntaxErrorNotification new setClass: self methodNode methodClass category: nil code: self methodNode source doitFlag: false errorMessage: errorMessage location: self start Marcus |
On Tue, Jun 28, 2016 at 9:31 PM, Marcus Denker <[hidden email]> wrote:
> > On 28 Jun 2016, at 15:09, Guillermo Polito <[hidden email]> > wrote: > > Ding dong Marcus! > > > … is on Holidays… with the option #optionParseErrors you can compile code > with syntax errors: wow! quite an intelligent bot you are there. written in Smalltalk? maybe when Marcus is back you can ask him to share the source ;) cheers -ben > > method := Smalltalk compiler > class: UndefinedObject; > options: #(+ optionParseErrors); > compile: 'errorMethod ^1+'. > method valueWithReceiver: nil arguments: #() > This is really compiled to raise a syntax error at runtime. see > > OCASTTranslator>>#visitParseErrorNode: anErrorNode > methodBuilder > pushLiteralVariable: #error -> anErrorNode asSyntaxErrorNotification; > send: #signal. > > with > > RBParseErrorNode>>#asSyntaxErrorNotification > ^SyntaxErrorNotification new > setClass: self methodNode methodClass > category: nil > code: self methodNode source > doitFlag: false > errorMessage: errorMessage > location: self start > > > Marcus |
Free forum by Nabble | Edit this page |