Re: [Pharo-users] Code completion in Pharo?

2018-05-26 Thread p...@highoctane.be
Try Cmd-q or Ctrl-q ( and right alt click on Windows).

Spotter also has suffixes like #im #cl #sen to be put after a few
keystrokes.

Spotter: shift-enter (who knows).

Phil

On Sat, May 26, 2018, 22:16 Tim Mackinnon  wrote:

> That’s exactly the exploratory attitude we like to see...
>
> I think the code completer is pluggable and can be selected in the
> settings (I think there are 2, and their history is probably in this list
> somewhere), so  you can try your own too.
>
> Tim
>
> Sent from my iPhone
>
>
>
> Sent from my iPhone
> On 26 May 2018, at 16:10, Andrzej Olszak  wrote:
>
> Hi Tim and Nicole,
>
> Thanks for great tips. The click+keyModifier actions are extremely useful,
> and combined with breakpoints make for a great way of 'peeking under the
> hood' of the existing features.
>
> Also, I've just found a perfect piece of real code to do some learning and
> experimenting on - it will be the code completion itself! ;-)
>
> Andrzej
>
> On Fri, May 25, 2018 at 10:47 AM, Nicole de Graaf  wrote:
>
>> Hi Andrzej,
>>
>> my way of doing it:
>>
>> Searching in the image what other guys are doing.
>>
>> Finder: asMorph
>>
>> and here you can find methods like
>>
>> #openAsMorph .. you can get a clue.
>>
>> or:
>>
>> ‘some text’ asMorph inspect ..
>> than you get the object and you can search the class and from here the
>> class the references.
>>
>> *All my steps are based on code reading not code completion.*
>>
>> Code completion I use more if I know what is should be and use the same
>> method names as the other developers.
>>
>> Nic
>>
>>
>> On 25 May 2018, at 03:12, andreo  wrote:
>>
>> Dear Pharoers,
>>
>> I'm just starting out with Pharo 6.1, and I'm trying to use code
>> completion
>> to interactively explore various objects and their messages. However, I'm
>> having difficulties doing this efficiently - I think I must be missing
>> something obvious, and I hope you can point me in the right direction.
>>
>> For instance, let's say I have the below in Playground:
>>
>> 'some text' asMorph
>>
>> and I would like to display the morph object as a window, but I don't know
>> the exact message name, or whether such a message exists at all. If I type
>> "Window", then the completion popup will show a long list of matching
>> messages, but won't show their documentation or argument names, so it will
>> be difficult to know exactly what these messages do.
>> I can see that one can do "Do it and go" on an expression and then browse
>> the available messages in Meta, but maybe there is simpler/faster way?
>>
>> How would an experienced Pharo user typically go about discovering the
>> right
>> messages in such situations?
>>
>> Best regards,
>> Andrzej
>>
>>
>>
>> --
>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>>
>>
>>
>


Re: [Pharo-users] Code completion in Pharo?

2018-05-26 Thread Tim Mackinnon
That’s exactly the exploratory attitude we like to see...

I think the code completer is pluggable and can be selected in the settings (I 
think there are 2, and their history is probably in this list somewhere), so  
you can try your own too.

Tim

Sent from my iPhone



Sent from my iPhone
> On 26 May 2018, at 16:10, Andrzej Olszak  wrote:
> 
> Hi Tim and Nicole,
> 
> Thanks for great tips. The click+keyModifier actions are extremely useful, 
> and combined with breakpoints make for a great way of 'peeking under the 
> hood' of the existing features.
> 
> Also, I've just found a perfect piece of real code to do some learning and 
> experimenting on - it will be the code completion itself! ;-)
> 
> Andrzej
> 
>> On Fri, May 25, 2018 at 10:47 AM, Nicole de Graaf  wrote:
>> Hi Andrzej,
>> 
>> my way of doing it:
>> 
>> Searching in the image what other guys are doing.
>> 
>> Finder: asMorph 
>> 
>> and here you can find methods like
>> 
>> #openAsMorph .. you can get a clue.
>> 
>> or:
>> 
>> ‘some text’ asMorph inspect .. 
>> than you get the object and you can search the class and from here the class 
>> the references.
>> 
>> All my steps are based on code reading not code completion.
>> 
>> Code completion I use more if I know what is should be and use the same 
>> method names as the other developers.
>> 
>> Nic
>> 
>> 
>>> On 25 May 2018, at 03:12, andreo  wrote:
>>> 
>>> Dear Pharoers, 
>>> 
>>> I'm just starting out with Pharo 6.1, and I'm trying to use code completion
>>> to interactively explore various objects and their messages. However, I'm
>>> having difficulties doing this efficiently - I think I must be missing
>>> something obvious, and I hope you can point me in the right direction. 
>>> 
>>> For instance, let's say I have the below in Playground: 
>>> 
>>> 'some text' asMorph 
>>> 
>>> and I would like to display the morph object as a window, but I don't know
>>> the exact message name, or whether such a message exists at all. If I type
>>> "Window", then the completion popup will show a long list of matching
>>> messages, but won't show their documentation or argument names, so it will
>>> be difficult to know exactly what these messages do. 
>>> I can see that one can do "Do it and go" on an expression and then browse
>>> the available messages in Meta, but maybe there is simpler/faster way? 
>>> 
>>> How would an experienced Pharo user typically go about discovering the right
>>> messages in such situations? 
>>> 
>>> Best regards, 
>>> Andrzej
>>> 
>>> 
>>> 
>>> --
>>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
> 


Re: [Pharo-users] Code completion in Pharo?

2018-05-26 Thread Andrzej Olszak
Hi Tim and Nicole,

Thanks for great tips. The click+keyModifier actions are extremely useful,
and combined with breakpoints make for a great way of 'peeking under the
hood' of the existing features.

Also, I've just found a perfect piece of real code to do some learning and
experimenting on - it will be the code completion itself! ;-)

Andrzej

On Fri, May 25, 2018 at 10:47 AM, Nicole de Graaf  wrote:

> Hi Andrzej,
>
> my way of doing it:
>
> Searching in the image what other guys are doing.
>
> Finder: asMorph
>
> and here you can find methods like
>
> #openAsMorph .. you can get a clue.
>
> or:
>
> ‘some text’ asMorph inspect ..
> than you get the object and you can search the class and from here the
> class the references.
>
> *All my steps are based on code reading not code completion.*
>
> Code completion I use more if I know what is should be and use the same
> method names as the other developers.
>
> Nic
>
>
> On 25 May 2018, at 03:12, andreo  wrote:
>
> Dear Pharoers,
>
> I'm just starting out with Pharo 6.1, and I'm trying to use code completion
> to interactively explore various objects and their messages. However, I'm
> having difficulties doing this efficiently - I think I must be missing
> something obvious, and I hope you can point me in the right direction.
>
> For instance, let's say I have the below in Playground:
>
> 'some text' asMorph
>
> and I would like to display the morph object as a window, but I don't know
> the exact message name, or whether such a message exists at all. If I type
> "Window", then the completion popup will show a long list of matching
> messages, but won't show their documentation or argument names, so it will
> be difficult to know exactly what these messages do.
> I can see that one can do "Do it and go" on an expression and then browse
> the available messages in Meta, but maybe there is simpler/faster way?
>
> How would an experienced Pharo user typically go about discovering the
> right
> messages in such situations?
>
> Best regards,
> Andrzej
>
>
>
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>
>
>


Re: [Pharo-users] Serving files with ZnServer

2018-05-26 Thread Hilaire

Le 26/05/2018 à 12:09, Sven Van Caekenberghe a écrit :

ZnStaticFileServerDelegate does not automatically generate an index for a 
directory.


Ok, understood.


BTW, you do no really need to go via files, you can just serve resources 
directly.

yes,  I was just trying.

Hilaire

--
Dr. Geo
http://drgeo.eu





Re: [Pharo-users] Serving files with ZnServer

2018-05-26 Thread Sven Van Caekenberghe
on macOS

server := ZnServer startDefaultOn: 9595.
server delegate: (
ZnStaticFileServerDelegate new
directory: '/Users/sven/' asFileReference ;
prefixFromString: 'files';
yourself).
server logToTranscript.

FileLocator home / 'small.html' writeStreamDo: [ :out | 
(ZnHtmlOutputStream on: out) 
tag: #h1 with: #Small;
tag: #p with: 'This is a small HTML document' ].

ZnClient new get: 'http://localhost:9595/files/small.html'.

ZnStaticFileServerDelegate does not automatically generate an index for a 
directory.

BTW, you do no really need to go via files, you can just serve resources 
directly.

> On 26 May 2018, at 10:28, Hilaire  wrote:
> 
> Hi,
> 
> On P7, I try to server files with ZnServer, but got trouble:
> 
> server := ZnServer startDefaultOn: 9595.
> server delegate: (
> ZnStaticFileServerDelegate new
> directory: '/home/hilaire' asFileReference ;
> prefixFromString: 'files';
> yourself).
> server logToTranscript.
> server start.
> 
> The browser pointed at http://localhost:9595/files/ only print:
> 
> Not Found /files/
> 
> 
> The log reflects the not found:
> 
> 2018-05-26 10:21:06 378 128292 Started ZnManagingMultiThreadedServer HTTP 
> port 9595
> 2018-05-26 10:21:10 379 552905 Connection Accepted 127.0.0.1
> 2018-05-26 10:21:10 380 552905 Connection Accepted 127.0.0.1
> 2018-05-26 10:21:10 381 990536 Request Read a ZnRequest(GET /files/) 25ms
> 2018-05-26 10:21:10 382 990536 Request Handled a ZnRequest(GET /files/) 4ms
> 2018-05-26 10:21:10 383 990536 Response Written a ZnResponse(404 Not Found 
> text/plain;charset=utf-8 19B) 2ms
> 2018-05-26 10:21:10 384 990536 GET /files/ 404 19B 6ms
> 
> Any idea?
> 
> Hilaire
> 
> -- 
> Dr. Geo
> http://drgeo.eu
> 
> 
> 




Re: [Pharo-users] Serving files with ZnServer

2018-05-26 Thread Norbert Hartl
What shall it do with the directory? Did you try to access a file?

Norbert

> Am 26.05.2018 um 10:28 schrieb Hilaire :
> 
> Hi,
> 
> On P7, I try to server files with ZnServer, but got trouble:
> 
> server := ZnServer startDefaultOn: 9595.
> server delegate: (
> ZnStaticFileServerDelegate new
> directory: '/home/hilaire' asFileReference ;
> prefixFromString: 'files';
> yourself).
> server logToTranscript.
> server start.
> 
> The browser pointed at http://localhost:9595/files/ only print:
> 
> Not Found /files/
> 
> 
> The log reflects the not found:
> 
> 2018-05-26 10:21:06 378 128292 Started ZnManagingMultiThreadedServer HTTP 
> port 9595
> 2018-05-26 10:21:10 379 552905 Connection Accepted 127.0.0.1
> 2018-05-26 10:21:10 380 552905 Connection Accepted 127.0.0.1
> 2018-05-26 10:21:10 381 990536 Request Read a ZnRequest(GET /files/) 25ms
> 2018-05-26 10:21:10 382 990536 Request Handled a ZnRequest(GET /files/) 4ms
> 2018-05-26 10:21:10 383 990536 Response Written a ZnResponse(404 Not Found 
> text/plain;charset=utf-8 19B) 2ms
> 2018-05-26 10:21:10 384 990536 GET /files/ 404 19B 6ms
> 
> Any idea?
> 
> Hilaire
> 
> -- 
> Dr. Geo
> http://drgeo.eu
> 
> 
> 




Re: [Pharo-users] Macros?

2018-05-26 Thread Norbert Hartl
I need to say that this is not a good use case. First and most important is 
that you should not have deployment switches in your code. Your system should 
be configured for a special deployment mode not detecting in code. Second but 
not least important you add references to test classes in your business logic. 
Usually you do not load test code in a production image. 

Couldn‘t resist, sorry

Norbert

> Am 26.05.2018 um 07:46 schrieb Clément Bera :
> 
> Just mentioning another use-case:
> 
> getDatabaseInstance
> ^ (Production CifTrue: [Database] CifFalse: [MockDatabase]) new
> 
> Since I use conditional compilation more often than just precompiling 
> constants.
> 
> I don't see an equivalent of asMethodConstant AST manipulation at runtime 
> strategy in the image for this case right now but it's probably a couple 
> lines of code with Reflectivity.
> 
>> On Sat, May 26, 2018 at 7:28 AM, Clément Bera  wrote:
>> 
>> 
>>> On Fri, May 25, 2018 at 10:44 PM, Esteban Lorenzano  
>>> wrote:
>>> 
>>> 
 On 25 May 2018, at 17:30, Clément Bera  wrote:
 
 What about a preprocessor like the Java preprocessors ? The Truffle 
 project relies heavily on that for high performance Java and it's quite 
 nice. It's difficult to do that in Smalltalk right now.
 
 I think if you want to do what are asking for you just need to write a 
 bytecode compiler extension.
 
 I did something similar in the past to have precomputed constants through 
 AST manipulation at compilation time. You can find it here with examples: 
 http://smalltalkhub.com/#!/~ClementBera/NeoCompiler. Once the code is 
 loaded you need to recompile the examples (NeoCompilerExample 
 withAllSubclassesDo: #compileAll.). With it you can write code such as:
 [ Smalltalk vm class ] Cvalue
 And depending if the compiler allowsPrecompilation or not, the bytecode 
 compiler generates:
 Smalltalk vm class 
 Or just a push literal with the precomputed value (the class 
 VirtualMachine).
>>> 
>>> this is not what #asMethodConstant provides?
>> 
>> Can you turn asMethodConstant On and Off so you have the constant in 
>> production and not a development time ? Typically at development time I 
>> change the constants generated a lot and I don't want to waste time 
>> recompiling all the time.
>> 
>> But yeah, my project is from 2014. I guess instead of preprocessing you 
>> could do everything at runtime with AST manipulation/recompilation like in 
>> asMethodConstant.
>> 
>> The main point of preprocessing IMO is to control performance, it's just 
>> easier for me to just look at the generated bytecode and change the 
>> preprocessor until it gets what I want, it's not always easy to run code 
>> that will change your method at runtime quickly so you can look at the 
>> bytecode generated.
>> 
>> Anyway, I am not convinced at all something like that should be in the base 
>> image.
>>  
>>> 
>>> Esteban
>>> 
 In the end I decided not to use this, but you can use it and extend it to 
 support more than just constants (any AST manipulation is possible).
 Just checked it works in Pharo 6.
 
> On Fri, May 25, 2018 at 4:26 PM, Stephan Eggermont  
> wrote:
> Debiller 777 
> wrote:
> > Well, I've already asked about adding new literals to pharo or
> Smalltalk in
> > general, however this time I have a better idea:
> > macros. Can they be added? Because if I understand correctly they may be
> > the only way to do that.
> 
> Why do you think they would be a good idea? We have powerful
> meta-programming facilities that are well understood and somewhat 
> supported
> by tooling. How do we get value out of macros?
> 
> Stephan
> 
> 
> 
 
 
 
 -- 
 Clément Béra
 https://clementbera.github.io/
 https://clementbera.wordpress.com/
>>> 
>> 
>> 
>> 
>> -- 
>> Clément Béra
>> https://clementbera.github.io/
>> https://clementbera.wordpress.com/
> 
> 
> 
> -- 
> Clément Béra
> https://clementbera.github.io/
> https://clementbera.wordpress.com/


[Pharo-users] Serving files with ZnServer

2018-05-26 Thread Hilaire

Hi,

On P7, I try to server files with ZnServer, but got trouble:

server := ZnServer startDefaultOn: 9595.
server delegate: (
ZnStaticFileServerDelegate new
    directory: '/home/hilaire' asFileReference ;
    prefixFromString: 'files';
    yourself).
server logToTranscript.
server start.

The browser pointed at http://localhost:9595/files/ only print:

Not Found /files/


The log reflects the not found:

2018-05-26 10:21:06 378 128292 Started ZnManagingMultiThreadedServer 
HTTP port 9595

2018-05-26 10:21:10 379 552905 Connection Accepted 127.0.0.1
2018-05-26 10:21:10 380 552905 Connection Accepted 127.0.0.1
2018-05-26 10:21:10 381 990536 Request Read a ZnRequest(GET /files/) 25ms
2018-05-26 10:21:10 382 990536 Request Handled a ZnRequest(GET /files/) 4ms
2018-05-26 10:21:10 383 990536 Response Written a ZnResponse(404 Not 
Found text/plain;charset=utf-8 19B) 2ms

2018-05-26 10:21:10 384 990536 GET /files/ 404 19B 6ms

Any idea?

Hilaire

--
Dr. Geo
http://drgeo.eu





Re: [Pharo-users] Macros?

2018-05-26 Thread Denis Kudriashov
2018-05-26 9:33 GMT+03:00 Clément Bera :

>
>
> On Sat, May 26, 2018 at 8:07 AM, Denis Kudriashov 
> wrote:
>
>> Hi
>>
>> 2018-05-26 8:46 GMT+03:00 Clément Bera :
>>
>>> Just mentioning another use-case:
>>>
>>> getDatabaseInstance
>>> ^ (Production CifTrue: [Database] CifFalse: [MockDatabase]) new
>>>
>>
>> I think following code will work:
>>
>> getDatabaseInstance
>>  ^ (Production ifTrue: [Database] ifFalse: [MockDatabase])
>> asMethodConstant new
>>
>>
>>
> Arf, obviously you try to work around the example. You can have anything
> in the block, not necessarily a constant.
>
> foo
>^ Condition  CifTrue: [self bar] CifFalse: [self baz]
>
> And I want the condition to be replaced by the contents of one block or
> the other, not just by a constant.
>

Yes, I see. It's different


>
>>>
>>>
>>> Since I use conditional compilation more often than just precompiling
>>> constants.
>>>
>>> I don't see an equivalent of asMethodConstant AST manipulation at
>>> runtime strategy in the image for this case right now but it's probably a
>>> couple lines of code with Reflectivity.
>>>
>>> On Sat, May 26, 2018 at 7:28 AM, Clément Bera 
>>> wrote:
>>>


 On Fri, May 25, 2018 at 10:44 PM, Esteban Lorenzano <
 esteba...@gmail.com> wrote:

>
>
> On 25 May 2018, at 17:30, Clément Bera  wrote:
>
> What about a preprocessor like the Java preprocessors ? The Truffle
> project relies heavily on that for high performance Java and it's quite
> nice. It's difficult to do that in Smalltalk right now.
>
> I think if you want to do what are asking for you just need to write a
> bytecode compiler extension.
>
> I did something similar in the past to have precomputed constants
> through AST manipulation at compilation time. You can find it here with
> examples: http://smalltalkhub.com/#!/~ClementBera/NeoCompiler. Once
> the code is loaded you need to recompile the examples (NeoCompilerExample
> withAllSubclassesDo: #compileAll.). With it you can write code such
> as:
> [ Smalltalk vm class ] Cvalue
> And depending if the compiler allowsPrecompilation or not, the
> bytecode compiler generates:
> Smalltalk vm class
> Or just a push literal with the precomputed value (the class
> VirtualMachine).
>
>
> this is not what #asMethodConstant provides?
>

 Can you turn asMethodConstant On and Off so you have the constant in
 production and not a development time ? Typically at development time I
 change the constants generated a lot and I don't want to waste time
 recompiling all the time.

 But yeah, my project is from 2014. I guess instead of preprocessing you
 could do everything at runtime with AST manipulation/recompilation like
 in asMethodConstant.

 The main point of preprocessing IMO is to control performance, it's
 just easier for me to just look at the generated bytecode and change the
 preprocessor until it gets what I want, it's not always easy to run code
 that will change your method at runtime quickly so you can look at the
 bytecode generated.

 Anyway, I am not convinced at all something like that should be in the
 base image.


>
> Esteban
>
> In the end I decided not to use this, but you can use it and extend it
> to support more than just constants (any AST manipulation is possible).
> Just checked it works in Pharo 6.
>
> On Fri, May 25, 2018 at 4:26 PM, Stephan Eggermont 
> wrote:
>
>> Debiller 777 
>> wrote:
>> > Well, I've already asked about adding new literals to pharo or
>> Smalltalk in
>> > general, however this time I have a better idea:
>> > macros. Can they be added? Because if I understand correctly they
>> may be
>> > the only way to do that.
>>
>> Why do you think they would be a good idea? We have powerful
>> meta-programming facilities that are well understood and somewhat
>> supported
>> by tooling. How do we get value out of macros?
>>
>> Stephan
>>
>>
>>
>>
>
>
> --
> Clément Béra
> https://clementbera.github.io/
> https://clementbera.wordpress.com/
>
>
>


 --
 Clément Béra
 https://clementbera.github.io/
 https://clementbera.wordpress.com/

>>>
>>>
>>>
>>> --
>>> Clément Béra
>>> https://clementbera.github.io/
>>> https://clementbera.wordpress.com/
>>>
>>
>>
>
>
> --
> Clément Béra
> https://clementbera.github.io/
> https://clementbera.wordpress.com/
>


Re: [Pharo-users] Macros?

2018-05-26 Thread Clément Bera
On Sat, May 26, 2018 at 8:07 AM, Denis Kudriashov 
wrote:

> Hi
>
> 2018-05-26 8:46 GMT+03:00 Clément Bera :
>
>> Just mentioning another use-case:
>>
>> getDatabaseInstance
>> ^ (Production CifTrue: [Database] CifFalse: [MockDatabase]) new
>>
>
> I think following code will work:
>
> getDatabaseInstance
>  ^ (Production ifTrue: [Database] ifFalse: [MockDatabase])
> asMethodConstant new
>
>
>
Arf, obviously you try to work around the example. You can have anything in
the block, not necessarily a constant.

foo
   ^ Condition  CifTrue: [self bar] CifFalse: [self baz]

And I want the condition to be replaced by the contents of one block or the
other, not just by a constant.


>>
>>
>> Since I use conditional compilation more often than just precompiling
>> constants.
>>
>> I don't see an equivalent of asMethodConstant AST manipulation at
>> runtime strategy in the image for this case right now but it's probably a
>> couple lines of code with Reflectivity.
>>
>> On Sat, May 26, 2018 at 7:28 AM, Clément Bera 
>> wrote:
>>
>>>
>>>
>>> On Fri, May 25, 2018 at 10:44 PM, Esteban Lorenzano >> > wrote:
>>>


 On 25 May 2018, at 17:30, Clément Bera  wrote:

 What about a preprocessor like the Java preprocessors ? The Truffle
 project relies heavily on that for high performance Java and it's quite
 nice. It's difficult to do that in Smalltalk right now.

 I think if you want to do what are asking for you just need to write a
 bytecode compiler extension.

 I did something similar in the past to have precomputed constants
 through AST manipulation at compilation time. You can find it here with
 examples: http://smalltalkhub.com/#!/~ClementBera/NeoCompiler. Once
 the code is loaded you need to recompile the examples (NeoCompilerExample
 withAllSubclassesDo: #compileAll.). With it you can write code such as:
 [ Smalltalk vm class ] Cvalue
 And depending if the compiler allowsPrecompilation or not, the bytecode
 compiler generates:
 Smalltalk vm class
 Or just a push literal with the precomputed value (the class
 VirtualMachine).


 this is not what #asMethodConstant provides?

>>>
>>> Can you turn asMethodConstant On and Off so you have the constant in
>>> production and not a development time ? Typically at development time I
>>> change the constants generated a lot and I don't want to waste time
>>> recompiling all the time.
>>>
>>> But yeah, my project is from 2014. I guess instead of preprocessing you
>>> could do everything at runtime with AST manipulation/recompilation like
>>> in asMethodConstant.
>>>
>>> The main point of preprocessing IMO is to control performance, it's just
>>> easier for me to just look at the generated bytecode and change the
>>> preprocessor until it gets what I want, it's not always easy to run code
>>> that will change your method at runtime quickly so you can look at the
>>> bytecode generated.
>>>
>>> Anyway, I am not convinced at all something like that should be in the
>>> base image.
>>>
>>>

 Esteban

 In the end I decided not to use this, but you can use it and extend it
 to support more than just constants (any AST manipulation is possible).
 Just checked it works in Pharo 6.

 On Fri, May 25, 2018 at 4:26 PM, Stephan Eggermont 
 wrote:

> Debiller 777 
> wrote:
> > Well, I've already asked about adding new literals to pharo or
> Smalltalk in
> > general, however this time I have a better idea:
> > macros. Can they be added? Because if I understand correctly they
> may be
> > the only way to do that.
>
> Why do you think they would be a good idea? We have powerful
> meta-programming facilities that are well understood and somewhat
> supported
> by tooling. How do we get value out of macros?
>
> Stephan
>
>
>
>


 --
 Clément Béra
 https://clementbera.github.io/
 https://clementbera.wordpress.com/



>>>
>>>
>>> --
>>> Clément Béra
>>> https://clementbera.github.io/
>>> https://clementbera.wordpress.com/
>>>
>>
>>
>>
>> --
>> Clément Béra
>> https://clementbera.github.io/
>> https://clementbera.wordpress.com/
>>
>
>


-- 
Clément Béra
https://clementbera.github.io/
https://clementbera.wordpress.com/


Re: [Pharo-users] Macros?

2018-05-26 Thread Denis Kudriashov
Hi

2018-05-26 8:46 GMT+03:00 Clément Bera :

> Just mentioning another use-case:
>
> getDatabaseInstance
> ^ (Production CifTrue: [Database] CifFalse: [MockDatabase]) new
>

I think following code will work:

getDatabaseInstance
 ^ (Production ifTrue: [Database] ifFalse: [MockDatabase])
asMethodConstant new



>
>
> Since I use conditional compilation more often than just precompiling
> constants.
>
> I don't see an equivalent of asMethodConstant AST manipulation at runtime
> strategy in the image for this case right now but it's probably a couple
> lines of code with Reflectivity.
>
> On Sat, May 26, 2018 at 7:28 AM, Clément Bera 
> wrote:
>
>>
>>
>> On Fri, May 25, 2018 at 10:44 PM, Esteban Lorenzano 
>> wrote:
>>
>>>
>>>
>>> On 25 May 2018, at 17:30, Clément Bera  wrote:
>>>
>>> What about a preprocessor like the Java preprocessors ? The Truffle
>>> project relies heavily on that for high performance Java and it's quite
>>> nice. It's difficult to do that in Smalltalk right now.
>>>
>>> I think if you want to do what are asking for you just need to write a
>>> bytecode compiler extension.
>>>
>>> I did something similar in the past to have precomputed constants
>>> through AST manipulation at compilation time. You can find it here with
>>> examples: http://smalltalkhub.com/#!/~ClementBera/NeoCompiler. Once the
>>> code is loaded you need to recompile the examples (NeoCompilerExample
>>> withAllSubclassesDo: #compileAll.). With it you can write code such as:
>>> [ Smalltalk vm class ] Cvalue
>>> And depending if the compiler allowsPrecompilation or not, the bytecode
>>> compiler generates:
>>> Smalltalk vm class
>>> Or just a push literal with the precomputed value (the class
>>> VirtualMachine).
>>>
>>>
>>> this is not what #asMethodConstant provides?
>>>
>>
>> Can you turn asMethodConstant On and Off so you have the constant in
>> production and not a development time ? Typically at development time I
>> change the constants generated a lot and I don't want to waste time
>> recompiling all the time.
>>
>> But yeah, my project is from 2014. I guess instead of preprocessing you
>> could do everything at runtime with AST manipulation/recompilation like
>> in asMethodConstant.
>>
>> The main point of preprocessing IMO is to control performance, it's just
>> easier for me to just look at the generated bytecode and change the
>> preprocessor until it gets what I want, it's not always easy to run code
>> that will change your method at runtime quickly so you can look at the
>> bytecode generated.
>>
>> Anyway, I am not convinced at all something like that should be in the
>> base image.
>>
>>
>>>
>>> Esteban
>>>
>>> In the end I decided not to use this, but you can use it and extend it
>>> to support more than just constants (any AST manipulation is possible).
>>> Just checked it works in Pharo 6.
>>>
>>> On Fri, May 25, 2018 at 4:26 PM, Stephan Eggermont 
>>> wrote:
>>>
 Debiller 777 
 wrote:
 > Well, I've already asked about adding new literals to pharo or
 Smalltalk in
 > general, however this time I have a better idea:
 > macros. Can they be added? Because if I understand correctly they may
 be
 > the only way to do that.

 Why do you think they would be a good idea? We have powerful
 meta-programming facilities that are well understood and somewhat
 supported
 by tooling. How do we get value out of macros?

 Stephan




>>>
>>>
>>> --
>>> Clément Béra
>>> https://clementbera.github.io/
>>> https://clementbera.wordpress.com/
>>>
>>>
>>>
>>
>>
>> --
>> Clément Béra
>> https://clementbera.github.io/
>> https://clementbera.wordpress.com/
>>
>
>
>
> --
> Clément Béra
> https://clementbera.github.io/
> https://clementbera.wordpress.com/
>