Then you might have used kind of named block params like MyClass >> [foo: aFoo bar: aBar | self foo: aFoo; bar: aBar] Le 8 févr. 2018 20:11, "Stephane Ducasse" <stepharo.self@gmail.com> a écrit :
Hi ben
This is not what I asked for :). In nautilus you do not have to switch mode to define a method.
Now about your proposal. I would like to be able the type tonel method definition
SomeClass >> echo: anObject [ ^ 42 ]
Tonel represents what I want for methods. This way students could just type nearly as in the books and I would change the book to reflect this. And people can decide either to type all the time the class or now.
Stef
On Thu, Feb 8, 2018 at 6:28 PM, Ben Coman <btc@openinworld.com> wrote:
On 9 February 2018 at 00:45, Ben Coman <btc@openinworld.com> wrote:
On 8 February 2018 at 16:22, Stephane Ducasse <stepharo.self@gmail.com> wrote:
Hi denis
- I would like to be able to define a method even in the class pane and that the system detects it automatically.
It would be nice to do it from anywhere including Playground with something like... Classname >> #methodname >> [ method source here ]
So I just tired a quick experiment...
Object subclass: #SomeClass instanceVariableNames: '' classVariableNames: '' package: 'MethodBuilderExperiment'
On SomeClass defined method... existingMethod ^1
On CompiledMethod defined method... >> blockClosure | newSource | newSource := self methodNode selector, String crlf, blockClosure sourceNode newSource allButFirst allButLast. self methodClass compile: newSource
Now each of the following lines can be evaluated...
SomeClass existingMethod "==> 1" SomeClass >> #existingMethod >> [ ^42]. SomeClass existingMethod "==> 42"
That should have been.
SomeClass new existingMethod "==> 1" SomeClass >> #existingMethod >> [ ^42]. SomeClass new existingMethod "==> 42"
And another experiment...
Object subclass: #MethodBuilder instanceVariableNames: 'methodClass methodSelector' classVariableNames: '' package: 'MethodBuilderExperiment'
On MethodBuilder defined method... class: aClass selector: aSelector methodClass := aClass. methodSelector := aSelector.
On MethodBuilder defined method... >> blockClosure |newSource| newSource := methodSelector, String crlf, blockClosure sourceNode newSource allButFirst allButLast. methodClass compile: newSource
On Behaviour re-defined method... compiledMethodAt: selector ^ self methodDict at: selector ifAbsent: [ MethodBuilder new class: self selector: selector
]
Now each of the following lines can be evaluated...
Someclass noMethod "==> error... Instance of SomeClass class did not understand #noMethod" SomeClass >> #noMethod >> [ ^42 ]. Someclass noMethod "==> 42"
And should have been... Someclass new noMethod "==> error... Instance of SomeClass class did not understand #noMethod" SomeClass >> #noMethod >> [ ^42 ]. Someclass new noMethod "==> 42"
I see that is a bit problematic for keyword messages, but with a tweak...
On MethodBuilder defined...
blockClosure |newSource| methodSelector isArray ifFalse: [ newSource := methodSelector ] ifTrue: [ newSource := ''. methodSelector do: [ :token | newSource := newSource , token asString, ' ' ] ]. newSource := newSource, String crlf, blockClosure sourceNode newSource allButFirst allButLast. methodClass compile: newSource
now the following can be evaluated...
SomeClass >>#(echo: anObject) >> [ ^anObject ]. SomeClass new echo: 'doyoulike'. "==> doyoulike"
Another form to define a method might be... SomeClass >> [ echo: anObject ^anObject ]
I think that looks better, but would require a loosening of block syntax.
cheers -ben
- Then we are starting to reverse engineering the ecompletion system and I'm learning it. I would like to know if Calypso can communicate with ecompletion the fact that we are defining a method. Then I have to check how the system can know that we are typing method argument when defining the signature but I think that this is not related to calypso.
Stef