Re: [Pharo-users] Pharo-users Question about the symbols

2016-04-08 Thread Henrik Nergaard
| s1 s2 |

s1 := 1234 asString.
s2 := 1234 asString.

s1 = s2. "true"
s1 == s2. "false"

s1 asSymbol = s2 asSymbol. "true"
s1 asSymbol == s2 asSymbol. "true"

(s1 class allInstances select: [:s | s = s1 ]) size. "2"
(s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1"

[ #stringA = #stringB ] bench. "26,812,864 per second"
[ 'StringA' = 'StringB' ] bench. "3,492,987 per second"

Best regards,
Henrik

-Original Message-
From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of Ben 
Coman
Sent: Friday, April 8, 2016 3:23 AM
To: Any question about pharo is welcome 
Subject: Re: [Pharo-users] Pharo-users Question about the symbols

A symbol is like a string, except that all symbols with the same value are in 
fact the same object; that is, every #hello symbol is the exact same object as 
every other #hello symbol.

See "identically equal" section here...
http://sdmeta.gforge.inria.fr/FreeBooks/ByExample/08%20-%20Chapter%206%20-%20Special%20Symbol.pdf

cheers, ben

On Fri, Apr 8, 2016 at 7:20 AM, Valentin Ryckewaert 
 wrote:
> Hello everyone,
>
> i'm learning Pharo and i'm having difficulties to understand the 
> symbols, what are they? How are they different of the ByteString ? Why 
> are they usefull ?
> Why should I put #string where I can put 'string' ?
>
> Thanks in advance for your answer.
> Valentin Ryckewaert



Re: [Pharo-users] Pharo-users Question about the symbols

2016-04-08 Thread Damien Cassou
Henrik Nergaard  writes:

> | s1 s2 |
>
> s1 := 1234 asString.
> s2 := 1234 asString.
>
> s1 = s2. "true"
> s1 == s2. "false"
>
> s1 asSymbol = s2 asSymbol. "true"
> s1 asSymbol == s2 asSymbol. "true"
>
> (s1 class allInstances select: [:s | s = s1 ]) size. "2"
> (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1"
>
> [ #stringA = #stringB ] bench. "26,812,864 per second"
> [ 'StringA' = 'StringB' ] bench. "3,492,987 per second"

very very nice summary.

-- 
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill



Re: [Pharo-users] Pharo-users Question about the symbols

2016-04-08 Thread Sven Van Caekenberghe

> On 08 Apr 2016, at 09:19, Damien Cassou  wrote:
> 
> Henrik Nergaard  writes:
> 
>> | s1 s2 |
>> 
>> s1 := 1234 asString.
>> s2 := 1234 asString.
>> 
>> s1 = s2. "true"
>> s1 == s2. "false"
>> 
>> s1 asSymbol = s2 asSymbol. "true"
>> s1 asSymbol == s2 asSymbol. "true"
>> 
>> (s1 class allInstances select: [:s | s = s1 ]) size. "2"
>> (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1"
>> 
>> [ #stringA = #stringB ] bench. "26,812,864 per second"
>> [ 'StringA' = 'StringB' ] bench. "3,492,987 per second"
> 
> very very nice summary.

YES!

> -- 
> Damien Cassou
> http://damiencassou.seasidehosting.st
> 
> "Success is the ability to go from one failure to another without
> losing enthusiasm." --Winston Churchill




Re: [Pharo-users] Pharo-users Question about the symbols

2016-04-08 Thread stepharo

+1


| s1 s2 |

s1 := 1234 asString.
s2 := 1234 asString.

s1 = s2. "true"
s1 == s2. "false"

s1 asSymbol = s2 asSymbol. "true"
s1 asSymbol == s2 asSymbol. "true"

(s1 class allInstances select: [:s | s = s1 ]) size. "2"
(s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1"

[ #stringA = #stringB ] bench. "26,812,864 per second"
[ 'StringA' = 'StringB' ] bench. "3,492,987 per second"

very very nice summary.






Re: [Pharo-users] Pharo-users Question about the symbols

2016-04-08 Thread Cyril Ferlicot Delbecque


On 08/04/2016 09:05, Henrik Nergaard wrote:
> | s1 s2 |
> 
> s1 := 1234 asString.
> s2 := 1234 asString.
> 
> s1 = s2. "true"
> s1 == s2. "false"
> 
> s1 asSymbol = s2 asSymbol. "true"
> s1 asSymbol == s2 asSymbol. "true"
> 
> (s1 class allInstances select: [:s | s = s1 ]) size. "2"
> (s1 asSymbol class allInstances select: [:s | s = s1 asSymbol ]) size. "1"
> 
> [ #stringA = #stringB ] bench. "26,812,864 per second"
> [ 'StringA' = 'StringB' ] bench. "3,492,987 per second"
> 
> Best regards,
> Henrik

Hi Henrik,

The class comment of Symbol is really not enough. It need improvement. I
think it would be good to add your examples at least in the class comment.

-- 
Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France



signature.asc
Description: OpenPGP digital signature


Re: [Pharo-users] Debugger in 4.0

2016-04-08 Thread Hilaire
I open a bug ticket,  it is important

https://pharo.fogbugz.com/f/cases/17961/Evaluating-instance-and-method-variable-in-Debugger
-- 
Dr. Geo
http://drgeo.eu




Re: [Pharo-users] FFI return by reference

2016-04-08 Thread Thibault Raffaillac
Is there something like a generic int value holder then?
> 
> I think in that case you need to pass an instance of FFIExternalValueHolder.
> 
> > Hi again,
> >
> > Does anyone know what is the state of return by reference in FFI?
> > Example:
> > glGetAttribute: attr into: value
> >  > errorCode>
> > ^ self nbCall: #( int SDL_GL_GetAttribute(SDL_GLattr attr, int
> > *value) )
> >
> > On my image (50666) it does nothing on value yet (if nil, remains nil, if
> > SmallInteger 0, remains 0).
> > (SDL2 glGetAttribute: 6 into: value) should return 16.
> > I've seen NBOpenGL put "out" before value in method header, should it
> > matter? (does not make it work though)
> > Last but not least, should we attach '*' to the type or variable for FFI
> > to understand it is a pointer?
> >
> > Cheers,
> > Thibault Raffaillac




Re: [Pharo-users] Passing nil with FFI

2016-04-08 Thread Esteban Lorenzano
Hi,

marshalling in UFFI is complex and sometimes not worthy, so we do not do 
auto-conversion between nil in smalltalk o zero to NULL (yes, I know NULL=0, 
but not for UFFI who is waiting a object type).
In this case (since it expects a kind of external object) you have to do: 

SDL2 glCreateContext: FFIExternalObject null.

Esteban


> On 07 Apr 2016, at 12:06, Thibault Raffaillac  
> wrote:
> 
> Hi,
> 
> I am having trouble passing nil to a function with FFI (i.e. NULL, i.e. 0).
> For example: SDL2 glCreateContext: nil.
> The function expects a subclass of FFIExternalObject, so calls instVarAt: 1 
> but nil has no such field!
> Am I missing something? (like a special nil instance of FFIExternalObject)
> Note however that putting nil works when FFI expects a String.
> 
> Cheers,
> Thibault Raffaillac
> 




Re: [Pharo-users] FFI return by reference

2016-04-08 Thread Esteban Lorenzano

> On 07 Apr 2016, at 14:15, Damien Pollet  wrote:
> 
> I think in that case you need to pass an instance of FFIExternalValueHolder.

yes.
you can take the test FFIExternalValueHolderTests>>testCall as an example. 

But since it uses anonymous classes it might require a better explanation, 
there is the class comment, but basically, you do this: 

1) Declare a class variable 

MyClass class>>initialize
INT_PTR := FFIExternalValueHolder ofType: ‘int’.

2) Replace "int *” in your function calls with your new type:

 glGetAttribute: attr into: value
^ self ffiCall: #( int SDL_GL_GetAttribute(SDL_GLattr attr, INT_PTR 
value) )

3) pass an instance of INT_PTR to get the value: 

| ptr value |

ptr := INT_PTR new.
self  glGetAttribute: anAttributeIDontKnow into: ptr.

value := ptr value.

Esteban


> 
> On 7 April 2016 at 17:42, Thibault Raffaillac  > wrote:
> Hi again,
> 
> Does anyone know what is the state of return by reference in FFI?
> Example:
> glGetAttribute: attr into: value
>  errorCode>
> ^ self nbCall: #( int SDL_GL_GetAttribute(SDL_GLattr attr, int 
> *value) )
> 
> On my image (50666) it does nothing on value yet (if nil, remains nil, if 
> SmallInteger 0, remains 0).
> (SDL2 glGetAttribute: 6 into: value) should return 16.
> I've seen NBOpenGL put "out" before value in method header, should it matter? 
> (does not make it work though)
> Last but not least, should we attach '*' to the type or variable for FFI to 
> understand it is a pointer?
> 
> Cheers,
> Thibault Raffaillac
> 
> 



Re: [Pharo-users] FFI return by reference

2016-04-08 Thread Esteban Lorenzano

> On 08 Apr 2016, at 11:34, Esteban Lorenzano  wrote:
> 
> 
>> On 07 Apr 2016, at 14:15, Damien Pollet > > wrote:
>> 
>> I think in that case you need to pass an instance of FFIExternalValueHolder.
> 
> yes.
> you can take the test FFIExternalValueHolderTests>>testCall as an example. 
> 
> But since it uses anonymous classes it might require a better explanation, 
> there is the class comment, but basically, you do this: 
> 
> 1) Declare a class variable 
> 
> MyClass class>>initialize
>   INT_PTR := FFIExternalValueHolder ofType: ‘int’.

as a larger explanation, this will create an anonymous subclass to keep “int” 
values, than later you can use as a type in your  function call. Some people 
would call this obscure, but is a good way of solving this problem (I adopted 
it from old NB). 
If you want to have a named class instead an anonymous class, you can just 
subclass FFIExternalValueHolder: 

FFIExternalValueHolder subclass: #MyIntPtr

and then implement typeDecl class method

MyIntPtr class>>typeDecl
^ ‘int'

and this will work as the anonymous class

> 
> 2) Replace "int *” in your function calls with your new type:
> 
>  glGetAttribute: attr into: value
> ^ self ffiCall: #( int SDL_GL_GetAttribute(SDL_GLattr attr, INT_PTR 
> value) )
> 
> 3) pass an instance of INT_PTR to get the value: 
> 
> | ptr value |
> 
> ptr := INT_PTR new.
> self  glGetAttribute: anAttributeIDontKnow into: ptr.
> 
> value := ptr value.
> 
> Esteban
> 
> 
>> 
>> On 7 April 2016 at 17:42, Thibault Raffaillac > > wrote:
>> Hi again,
>> 
>> Does anyone know what is the state of return by reference in FFI?
>> Example:
>> glGetAttribute: attr into: value
>> > errorCode>
>> ^ self nbCall: #( int SDL_GL_GetAttribute(SDL_GLattr attr, int 
>> *value) )
>> 
>> On my image (50666) it does nothing on value yet (if nil, remains nil, if 
>> SmallInteger 0, remains 0).
>> (SDL2 glGetAttribute: 6 into: value) should return 16.
>> I've seen NBOpenGL put "out" before value in method header, should it 
>> matter? (does not make it work though)
>> Last but not least, should we attach '*' to the type or variable for FFI to 
>> understand it is a pointer?
>> 
>> Cheers,
>> Thibault Raffaillac
>> 
>> 
> 



Re: [Pharo-users] Nesting Builders in Roassal

2016-04-08 Thread Evan Donahue
Hello,

I got that working, and a bit more besides, and things are starting to look
pretty good. However, I've run into another issue I'm not sure how to
resolve. Recognizing that, as you mentioned, nested builders are something
of a bleeding edge feature, I'm happy to try to contribute code if what I'm
trying to do isn't already implemented. My question now is how to adjust the
size and shape of the nested, builder-produced elements. In the example code
you posted, is it possible to 

1) remove the square borders from the pie graphs, and
2) make the pie graphs different sizes based on, for instance, the size of
the array they represent?

This second question is also relevant for sizing the pie graphs in
proportion to other elements such as labels. Witness the uneven proportions
between the pie charts and a label added to the display:

v := RTView new.
data := #((1) (2) (1 2)).
es := data collect: [ :d |
   b := RTPieBuilder new.
   b interaction popupText.
   b objects: d.
   b slice: #value.
   b build.
b view asElement.
].
v add: (RTLabel new elementOn: 'label').
v addAll: es.
RTCellLayout new lineItemsCount: 3; on: es.
RTMetricNormalizer new
view: v;
elements: v elements;
distinctColor.
v 

Normally, I gather, this is done by adding size and shape info to the
element factory before it produces its elements. Since the builders do not
appear to have been intended to fill this role initially, however, I can't
seem to find any corresponding inputs for size or shape of their generated
elements as nested in another builder's view.

Cheers,
Evan



--
View this message in context: 
http://forum.world.st/Nesting-Builders-in-Roassal-tp4885185p4889195.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.