Re: [Pharo-users] Stylistic question: private helper vs extension method?

2017-08-09 Thread Henrik Johansen

> On 8 Aug 2017, at 22:39 , Herby Vojčík  wrote:
> 
> Hello!
> 
> I've got this portion in my delegate:
> 
>   requestPayload ifNotNil: [ uuidKeys do: [ :each |
>   requestPayload at: each ifPresent: [ :s | 
> requestPayload at: each put: (UUID fromString: s) ] ] ].
>   responsePayload := self towergame clientSync: requestPayload.
>   responsePayload ifNotNil: [ uuidKeys do: [ :each |
>   responsePayload at: each ifPresent: [ :uuid | 
> responsePayload at: each put: uuid asString ] ] ].
> 
> Now I would gladly use something like Dictionary >> at:ifPresentTransform: 
> aBlock. But it is not present, so I have two choices:
> 
>  1. Add it as extension method, but then it may clash if someone else has 
> similar idea.
>  2. Add private helper TowergameDelegate >> dict:at:ifPresentTransform:, 
> which is longer and needs additional self receiver.
> 
> Which is preferable?
> 
> Herby

Following existing convention, an extension would be named #at:ifPresentPut:

I wonder though, wouldn't it be simpler to just put(UUID fromString: s) in the 
first place, and convert (dict at: uuidKey) in the accesses that needs it (or 
vice versa)?
Shifting the class of values like this seems like it could be a nightmare to 
debug and/or extend in the future remaining confident all uses will occur in 
the correct/expected order...

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP


Re: [Pharo-users] Pharo Object Model

2017-02-10 Thread Henrik Johansen

> On 10 Feb 2017, at 13:04 , Oleksandr Zaytsev  wrote:
> 
> Hello,
> 
> I'm trying to understand the logic behind The Pharo Object Model.
> 
> Rule 3 states that every class in Pharo has a subclass. I was expecting some 
> cool loop, like in the case of Metaclass, which is an instance and also a 
> class of Metaclass class. But ProtoObject, which is the root of an 
> inheritance hierarchy does not seem to have a superclass (ProtoObject 
> superclass answers nil, which is not a class).
> 
> Does this mean that Pharo Object Model is inconsistent? Is ProtoObject an 
> exception of the third rule?
> 
> If you think about it, an inheritance hierarchy can't have a loop, because 
> otherwise, when looking for a nonexistent method in superclasses, Pharo would 
> be stuck in that loop.
> 
> So why is there even a loop in instance hierarchy (Metaclass class)? Does it 
> have a purpose, or is it there only to satisfy the second rule of the Object 
> Model? Because if the consistency of third rule can not be satisfied, 
> wouldn't it be better to add two exceptions to the model?
> 
> Please correct me if my understanding or reasoning is wrong.
> 
> Thanks!

Rule 3 says every class has a superclass; it does not say the superclass must 
be a class. (but it must be an object, as per #1)
Hence a superclass of nil isn't inconsistent (as nil is an object), and is a 
valid way to terminate the inheritance hierarchy.

Metaclass class class  = Metaclass  is necessary not to satisfy #2, but to 
satisfy both #1 and #2.
Rule 2, states that every object is an instance of a class.
Classes are also objects according to #1, and as such are instances of a class 
(Metaclass), so the circular definition when it comes to Metaclass is needed to 
satisfy both.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP


Re: [Pharo-users] [Pharo-user] Does SSDP package supposed to work on Pharo 6?

2017-02-09 Thread Henrik Johansen

> On 9 Feb 2017, at 16:10 , Denis Kudriashov  wrote:
> 
> Hi.
> Question probably to Henrik.
> 
> I try SSDP  on latest Pharo 6 and 
> code for server and client signal primitive error on 
> #primGetAddressInfoHost:service:flags:family:type:protocol:.
> 
> Do you know about such problems? Does it VM or code needs to be adapted for 
> Pharo6?
> 
> 

Yes, there are some errors that can crop up, usually related to hostname 
resolution wrt. domains, I've seen the same...
Running DNS resolution to get the available interfaces is a kludge, I've yet to 
find a good cross-platform solution short of writing new network primitives to 
query interfaces directly (which I haven't done yet :/ ).

In SSDPParticipant >> hostName, there's a special branch for OSX that (I think) 
was added to solve similar prim errors under El Capitan, IIRC, it worked "on my 
machine" (when I had the same error running Sierra, when connected to a network 
with a domain) if I removed the branch, stripping domain consistently.


What could (no, should) be done, is add API to start participants running on 
the default interface (ie, create single sockets on 0.0.0.0), rather than try 
to start listening on all available, for 99% of cases, that's probably 
sufficient...

If you'd like to add that, tell me, and I'll add you to contributors.

Cheers,
Henry






signature.asc
Description: Message signed with OpenPGP


Re: [Pharo-users] Deployment pharo with multiple instances and voyage

2017-01-26 Thread Henrik Johansen

> On 25 Jan 2017, at 22:39 , Alejandro Infante  
> wrote:
> 
> Cool! Thanks for the answers!
> 
> Norbert mentions something interesting about references. 
> I have found that even though on each query mongo get the up-to-date version 
> of the objects, it does not install the proxies to look for the up-to-date 
> versions of the references of the queried object.
> 
> I made the following experiment:
> Having two images 1 and 2 and two classes A and B, each of them having one 
> instance variable.
> —
> Image 1 (Create two objects, “a” referencing “b”)
> [ |a b|
> a := A new.
> b := B new
> a setInstVar: b.
> b setInstVar: ‘foo'.
> b save.
> a save.
> ]
> 
> Image 2 (Mutates the second object, but the first is not changed)
> [
> b := (repository selectAll: A) first instVar.
> b setInstVar: ‘bar’.
> b save.
> ]
> 
> Image 1 (Query the first object and access to the referenced object)
> [
> b := (repository selectAll: A) first instVar.
> b instVar. “-> foo”
> b := (repository selectAll: B) first.
> b instVar. “-> bar"
> ]
> 
> This little experiment showed me that I cannot trust on the state of other 
> objects that I have not explicitly queried for. 
> 
> Is there any way of solving this without creating new instances of voyage 
> repositories for each request?
> 
> Thanks!
> Alejandro

Three, actually ;)

- Accept that an image will contain some stale values, and deal with conflicts 
at save time.
This is the most performant/scalable.
- Always save only root objects
More overhead since there's more likeliness of cache misses and actual reloads, 
but you can be sure any query will return the freshest value.
- Extend retrieveObjectOf:json: to either replace doc refs with proxies, or do 
eager (recursive) lookup of whether cached versions of referenced documents are 
up-to-date when returning a cached object.

In reality, only the first really makes sense; as you can never guarantee how 
long a queried object stays current.

Cheers,
Henry


Re: [Pharo-users] understanding existing code

2017-01-06 Thread Henrik Johansen

> On 5 Jan 2017, at 20:24 , Siemen Baader  wrote:
> 
> Hi All,
> 
> I may be missing the obvious, but what are good strategies to understand the 
> structure of existing code? Specifically, I'm trying to understand more of 
> PharoJS to solve my own problems and eventually also to contribute back - but 
> this is a general question.
> 
> There is this one MOOC exercise: 
> http://rmod-pharo-mooc.lille.inria.fr/MOOC/Exercises/Exercises-Pillar/Pillar-Questions.pdf
>  
> 
>  that helps, and reading tests and comments helps if they exist. But I often 
> get trapped in drilling down a long call stack and opening many, many browser 
> windows, a new one for every message send to a new class.
> 
> While writing this it occured to me that I can use the debugger to follow a 
> call stack by putting a breakpoint in the top level method, then stepping 
> down using the debugger. There is also a MOOC lecture on that that I will 
> look at again,  
> http://rmod-pharo-mooc.lille.inria.fr/MOOC/Videos/W5/C019-W2S-VideosDebugger1-UsingTheDebugger-V2-HD_720p_4Mbs.m4v
>  
> .
> 
> Any tips? I think I don't see the forest for the trees here I'm afraid :)
> 
> thanks,
> Siemen

A break once + debugger is a lifesaver if what you really want is a sequence 
diagrams of a specific operation; for general structure, the browser is usually 
a better place to start.

In a well-structured package, the different tags will usually also give a good 
indication about the class collaboration structure (or, sometimes, lack 
thereof), or at least the areas that are worth investigating.

Some structural pattern uses are quite easy to spot using the class hierarchy 
view (at least when not restricted to current package...), such as visitors and 
polymorphic delegation.
Searching base class references /senders of the polymorphic methods in such 
cases, will usually progressively take you to classes operating at higher 
abstraction levels; where the class comment are more likely to describe 
significant pieces of functionality.
(Some anti-patterns can also be spotted browsing the methods in a polymorphic 
base class, such as large methods on a super that has overriddes, usually 
implying copy-pasta-edit, rather than a habit of extracting the bits that 
actually differ) 

Class collaboration is an area that can be a nuisance to get a good picture of 
with the standard tools; senders/implementors will usually do the trick when 
interested in a single area (in a manner similar to the debugger), for a more 
complete picture, loading Roassal and scripting your own visualizations, or 
going full throttle and using Moose (which includes a useful set of premade 
ones, probably/hopefully including scoped collaboration) may be worth the 
effort.

Cheers,
Henry



Re: [Pharo-users] Cog VM on Raspberry Pi ?

2016-10-19 Thread Henrik Johansen

> On 18 Oct 2016, at 11:11 , Sven Van Caekenberghe  wrote:
> 
> 
> Is there still a stack VM (PharoS for ARM, 5.0) ?

I downloaded the one you linked 
(http://files.pharo.org/vm/pharoS/raspbian/latest.zip 
), but it was a pre-spur 
VM, so I had to use 50496 from the "preSpur" folder.
It didn't recognize the -nodisplay parameter, so I had to open image normally 
to do tinyBenchmarks.
Performance was fairly bad compared to Cog Spur (34M bytecodes, 2M sends), and 
in general not suitable for live editing of a Pharo image at all (8 seconds to 
open a browser, etc), so if a newer does not exist, I doubt it makes sense to 
spend effort creating one that reads Spur images other than as an intellectual 
exercize with a Cog VM available.

Cheers,
Henry

Version infos of vms I've ran, in order of age:

http://www.mirandabanda.org/files/Cog/VM/VM.r3427/cogspurlinuxhtARM-15.33.3427.tgz
 

 :

./phcogspurlinuxhtRPi/pharo -version
5.0-201610142319  Sat Oct 15 02:45:47 UTC 2016 gcc 4.9.2 [Production Spur VM]
CoInterpreter VMMaker.oscog-eem.1959 uuid: 2784931a-d7ba-431a-be8c-ec79b1e55684 
Oct 15 2016
StackToRegisterMappingCogit VMMaker.oscog-eem.1959 uuid: 
2784931a-d7ba-431a-be8c-ec79b1e55684 Oct 15 2016
VM: 201610142319 https://github.com/OpenSmalltalk/opensmalltalk-vm.git $ Date: 
Sat Oct 15 00:19:53 2016 +0100 $
Plugins: 201610142319 https://github.com/OpenSmalltalk/opensmalltalk-vm.git $
Linux testing-gce-874b9d32-9a0b-447e-98d4-15ee5b4feaec 4.4.0-42-generic 
#62~14.04.1-Ubuntu SMP Fri Oct 7 23:15:48 UTC 2016 armv7l GNU/Linux
plugin path: ./phcogspurlinuxhtRPi/lib/pharo/5.0-201610142319 [default: 
/home/veloxit/phcogspurlinuxhtRPi/lib/pharo/5.0-201610142319/]

Included by nuscratch:

squeak -version
5.0-201608180858  Mon Aug 22 18:41:57 PDT 2016 gcc 4.9.2 [Production Spur VM]
CoInterpreter VMMaker.oscog-cb.1919 uuid: 00a8dd2a-bc8d-4552-b400-be781c8aabec 
Aug 22 2016
StackToRegisterMappingCogit VMMaker.oscog-cb.1919 uuid: 
00a8dd2a-bc8d-4552-b400-be781c8aabec Aug 22 2016
VM: 201608180858 tim@Diziet.local:Documents/Squeak/Rasbian-VM/vm $ Date: Thu 
Aug 18 10:58:48 2016 +0200 $
Plugins: 201608180858 tim@Diziet.local:Documents/Squeak/Rasbian-VM/vm $
Linux Pi-3B-1 4.4.9-v7+ #884 SMP Fri May 6 17:28:59 BST 2016 armv7l GNU/Linux
plugin path: /usr/lib/squeak/5.0-201608180858 [default: 
/usr/lib/squeak/5.0-201608180858/]

http://files.pharo.org/vm/pharoS/raspbian/latest.zip 
 :

./PharoS/PharoS --version
3.9-7 #1 Thu Apr  9 14:59:10 CEST 2015 gcc 4.6.3 [Production ITHB VM]
StackInterpreter VMMaker.oscog-jeanbaptistearnaud.828 uuid: 
ba8d2ed6-70b9-4309-8bf0-9eda9c0d1c2d Apr  9 2015
https://github.com/pharo-project/pharo-vm.git Commit: 
32d18ba0f2db9bee7f3bdbf16bdb24fe4801cfc5 Date: 2015-03-24 11:08:14 +0100 By: 
Esteban Lorenzano  Jenkins build #128
Linux pharo-contribution-raspberrypi-linux 3.2.0-58-generic #88-Ubuntu SMP Tue 
Dec 3 17:37:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
plugin path: /home/veloxit/PharoS/ [default: /home/veloxit/PharoS/]

squeak.old (aka squeak , without nuscratch installed) (shell script doesn't 
forward to actual vm if not provided image path, hence the absolute):

/usr/lib/squeak/4.10.2-2614/squeakvm -version
4.10.2-2614 #1 XShm Sat Nov  8 01:32:22 UTC 2014 /usr/bin/cc
Linux bm-wb-01 3.16-trunk-armmp #1 SMP Debian 3.16-1~exp1 (2014-08-09) armv7l 
GNU/Linux
plugin path: /usr/lib/squeak/4.10.2-2614/ [default: 
/usr/lib/squeak/4.10.2-2614/]



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Cog VM on Raspberry Pi ?

2016-10-19 Thread Henrik Johansen

> On 18 Oct 2016, at 6:27 , Sven Van Caekenberghe  wrote:
> 
>>> "https://bintray.com/opensmalltalk/vm/download_file?file_path=cog_linux32ARMv6_pharo.cog.spur_201610142319.tar.gz;

That's the one I downloaded/ran Pharo on.
Like Todd said, there's also a Spur VM shipped with raspbian (as part of 
nuscratch package, located in /usr/lib/squeak/5.*).
Unless you've already uninstalled scratch/is running on an OS other than 
Raspbian, downloading a Squeak image and running the tinyBenchmarks in an image 
launched by
squeak $PathToMyImage should give a good baseline, on my machine it yields 
comparable tinyBenchmark numbers to the above Pharo build.
(In fact, it runs Pharo 6 images as well, the difference is mostly in plugins 
it seems. I guess you'll encounter errors if opening a file browser that 
attempts to use the extended FilePlugin prims, for example)

I'd recommend focusing on verifying any externally interacting parts you intend 
to use work correctly, since that's generally the area that's most spotty.
For instance, while FFI plugin ships with Pharo VM, you may (as I did on 
cursory testing with the vm linked above) get failing float/double call tests 
(60262 image), or downright crashes due to illegal instructions (latest 5.0 
image)
OSProcessPlugin shipped (externally) with the squeak cog vm has been sort of 
hit-and-miss, on above pharo vm it's built internal and seems to be working 
(but curiously, has no canonical source version from which it was generated in 
the Modules list...).

If you plan on developing on the Pi rather than just deploying to, switching to 
Bitmapped Fonts asap is a good idea; iirc the work that was done to provide 
optimized arm-assembly primitives included (bitmap) font rendering.
Disabling auto-complete and syntax-highlighting (that seem to tend to cause 
frequent noticeable pauses), and commenting out 
"write-entire-contents-to-file-every-keystroke" functionality from Playground 
code (so your SD-card doesn't die a premature death), are other small ways to 
make a less jarring experience of it.

Or, framework use allowing, you could save yourself a lot of work flow 
interruption frustration and develop using a Squeak image instead.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Cog VM on Raspberry Pi ?

2016-10-18 Thread Henrik Johansen

> On 17 Oct 2016, at 8:43 , Sven Van Caekenberghe  wrote:
> 
> Hi,
> 
> Does a (faster) Cog VM for the Raspberry Pi actually exist ?
> 
> I tried comparing the latest OpenSmalltalk VM with some older ones, only to 
> find that they are all equally fast (slow actually):
> 
> pi@raspberrypi ~/Pharo $ ./pharo -nodisplay Pharo.image printVersion
> [version] 5.0 #50581
> 
> "http://files.pharo.org/vm/pharoS/raspbian/latest.zip;
> 
> pi@raspberrypi ~/Pharo $ ./pharo -nodisplay Pharo.image eval '1 
> tinyBenchmarks'
> '167429692 bytecodes/sec; 11160247 sends/sec'
> 
> "http://www.mirandabanda.org/files/Cog/VM/VM.r3427/cogspurlinuxhtARM-15.33.3427.tgz;
> 
> pi@raspberrypi ~/Pharo $ ./products/phcogspurlinuxhtRPi/pharo -nodisplay 
> Pharo.image eval '1 tinyBenchmarks'
> '166992824 bytecodes/sec; 11337746 sends/sec'
> 
> "https://bintray.com/opensmalltalk/vm/download_file?file_path=cog_linux32ARMv6_pharo.cog.spur_201610142319.tar.gz;
> 
> pi@raspberrypi ~/Pharo $ ./products/phcogspurlinuxhtRPi/pharo -nodisplay 
> Pharo.image eval '1 tinyBenchmarks'
> '166992824 bytecodes/sec; 11337746 sends/sec'
> 
> That is no significant difference on a RPi 3, at all. Is this normal ? Am I 
> missing something ?
> 
> Thx,
> 
> Sven
> 
> PS: Just for reference, my Mac Book Pro is 10 times faster
> 
> 1 tinyBenchmarks  "'1323852617 bytecodes/sec; 174185794 sends/sec'"

Are you 100% sure you benched different VM's?
A stack VM (PharoS) getting the same results as a Spur VM 
(cog_linux32ARMv6_pharo.cog.spur_201610142319.tar.gz) is rather suspicious...

At least on my Pi3, the spur Cog VM gives  numbers around 250M bytecodes/160M 
sends
which, while still "slow", is a decent bump in speed compared to what you're 
seeing.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Pharo not running with macOS Sierra

2016-09-21 Thread Henrik Johansen

> On 21 Sep 2016, at 2:07 , MartinW  wrote:
> 
> Hello,
> 
> i just updated to macOS Sierra, and Pharo now starts with an empty black
> window and 100% CPU load and stays like this forever.
> Any ideas?
> 
> Best regards,
> Martin.

It's not an "official" official release, but the following link to a new VM 
build was posted on Slack yesterday; two user have reported it working 
("briefly" and "for several hours" respectively) on Sierra so far:
https://bintray.com/estebanlm/pharo-vm/build/201609201407#files 


Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] UFFI cleanup of externally allocated memory (was Re: UFFI const, unsigned, opaque-ish types)

2016-09-12 Thread Henrik Johansen

> On 07 Sep 2016, at 5:38 , Ben Coman  wrote:
> 
> On Wed, Sep 7, 2016 at 10:42 PM, Ben Coman  > wrote:
>> On Wed, Sep 7, 2016 at 9:09 PM, Esteban Lorenzano  
>> wrote:
>>> 
>>> On 07 Sep 2016, at 14:56, Ben Coman  wrote:
>>> 
>>> On Tue, Sep 6, 2016 at 8:08 PM, Esteban Lorenzano 
>>> wrote:
>>> 
>>> Hi,
>>> 
>>> sorry for arriving so late to this, but I was on holidays :)
>>> this is how autoRelease works:
>>> 
>>> 1) #autoRelease of an object registers object for finalisation with a
>>> particular executor. Then behaviour is divided:
>>> 
>>> 2.1.1) for ExternalAddresses, it just registers in regular way, who will
>>> call #finalize on GC
>>> 2.1.2) finalize will just call a free assuming ExternalAddress was allocated
>>> (which is a malloc)
>>> 
>>> 2.2.1) for all FFIExternalReference, it will register for finalisation what
>>> #resourceData answers (normally, the handle of the object)
>>> 2.2.2) finalisation process will call the object
>>> class>>#finalizeResourceData: method, with the #resourceData result as
>>> parameter
>>> 2.2.3) each kind of external reference can decide how to free that data (by
>>> default is also just freeing).
>>> 
>>> An example of this is how CairoFontFace works (or AthensCairoSurface).
>>> 
>>> 
>>> 
>>> At the bottom of FFIExternalResourceExecutor class comment I read...
>>>   "Note that in #finalizeResourceData: you cannot
>>>access any other properties of your instance,
>>>since it is already garbage collected."
>>> 
>>> But in my experiments it seems okay to access instance variables in
>>> #finalize.
>>> For example...
>>> 
>>> CXString >> autoRelease
>>>  self class finalizationRegistry add: self
>>> 
>>> CXString >> finalize
>>>   Transcript crShow: 'Finalizing CXString ' ; show: self private_flags.
>>>   self dispose.
>>>   Transcript show: ', done!'.
>>> 
>>> CXString >>private_flags
>>>   "This method was automatically generated"
>>>   ^handle unsignedLongAt: 5
>>> 
>>> Libclang getClangVersion autoRelease.
>>> Smalltalk garbageCollect.
>>> "==> Finalizing CXString 1, done! "
>>> 
>>> 
>>> Is this an unlucky coincidence?   Or maybe something changed from NB
>>> to UFFI?  (There is a reference to NB there)
>>> 
>>> 
>>> yes, is a coincidence.
>>> the idea of using #finalizeResourceData: is that you keep minimal
>>> information (in general, just the handle)… this way we ensure instances will
>>> be collected because we will not have circular references (preventing the
>>> weakregistry to work).
>>> 
>>> In general, you can always implement as you did it, but I would prefer the
>>> #finalizeResourceData: approach, even for structures.
>>> The only reason it is not implemented is because I didn’t reach the
>>> necessity, then I just skipped it (not in purpose, it was not in my head
>>> :P), but now is a good moment to implement it… if you want it :)
>> 
>> Thanks for the offer, but hold off for the moment.  I think I actually
>> need more than just finalization session management.  To get a real
>> displayable string requires calling the clang_getCString() library
>> function.  I imagine I'd like to call this from  CXString>>printOn: --
>> but this of course this would break after restarting the image.
>> 
>> extern "C" {
>> const char *clang_getCString(CXString string) {
>>   
>>   return static_cast(string.data);
>> }}
>> 
>> typedef struct {
>>  const void *data;
>>  unsigned private_flags;
>> } CXString;
>> 
>> So I think I need to register CXString with SessionManager to set *data <-- 0
>> on startup.
>> 
>> An alternative might be adding a session variable to CXString,
>>FFIExternalStructure subclass: #CXString
>>instanceVariableNames: 'session'
>>classVariableNames: ''
>>poolDictionaries: 'CXStringFlag'
>>package: 'Libclang'
>> 
>> except doing so crashes when calling
>> getClangVersion
>>   ^ self ffiCall: #( CXString clang_getClangVersion () ) module: Libclang
> 
> So this worked...
> 
>  CXString >> resetData
>  handle unsignedLongAt: 1 put: 0.
> 
>  CXString class >> startUp: resuming
>  resuming
>  ifTrue: [ self allInstances do: [ :cxs | cxs resetData ] ].
> 
>  CXString class >> initialize
>  "self initialize"
>  SessionManager default registerSystemClassNamed: self name
> 
> 
> Now immediate after a save/restart, doing...
>CXString allInstances first getString   "==> UndefinedObject(nil)"
> instead of crashing the VM.
> 
> Can you see/guess any traps hidden from me? Now I wonder early it is
> practical to prioritise such a reset.  My first thought is at least
> before #printString starts getting called ??

For traps, there's the assumption in resetData that pointer stored in handle is 
unsignedLong-sized.
Shouldn't there be auto-generated accessors for #data you can use instead to 
change the value to Pointer void?

Cheers,
Henry



Re: [Pharo-users] i18n & Unicode support in Pharo

2016-08-17 Thread Henrik Johansen

> On 17 Aug 2016, at 9:08 , Gour  wrote:
> 
> Hello,
> 
> just starting with Pharo and I'm thinking about i18n/l10n capabilities
> within environment to make one's app read for several langauges.
> 
> I've found out I18n (http://smalltalkhub.com/#!/~TorstenBergmann/I18N)
> project but it seems there are no new contrubutions in last 2 years.
> 
> I've also discovered 'Unicode project' thread on dev-list, but would
> like to get some pointer about the current (5.0 <= Pharo < 6) state of
> affairs in regard writing multi-language-capable and Unicode-aware apps
> in Pharo?
> 
> 
> Sincerely,
> Gour


For the translation part of l10n, there's also a package providing gettext 
support if needed.
locale support is limited to an API similar to *nix locales.

"Unicode-aware" is a wide topic, as reflected by the plethora of functional 
bits and bobs defined by different parts of the standard.
(With base image)
Can you represent all Unicode string? Yes.
Can you pass them to other systems in Unicode encodings? Yes.
Is the text renderer (in image) capable of displaying Unicode code points? Yes, 
if glyph is included in fonts.
(With Unicode project)
Can you query  Unicode properties of any codepoint? Yes
Can you normalize strings in the different forms? Yes.
Can you sort strings in Unicode collate order? Yes.
(With both)
Can you sort strings in CLDR-locale collate order? No.
Can you do regexp as per the Unicode spec? No.
Does the text renderer (in image) heed Unicode properties such as RTL and 
combining marks? No

Depending on what you want to do, the base image capabilities may be considered 
sufficient for writing multi-language-capable apps,
but for more advanced Unicode functionality, the groundworks is there, (ie, 
querying properties, normalization, the core collate algorithm) but many 
practical uses are as of yet unimplemented, the complete lack of CLDR support 
ranking high.

Cheers,
Henry

The big eyesore in


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] UPnP/IGD implementation

2016-07-26 Thread Henrik Johansen
You don't use SSDP to do the tweaking, but to discover the devices that are 
available to tweak.
Tweaking is subsequently carried out using SOAP/XML.

An an uninformed guess, I'd imagine use could look a bit like this:

SSDPClient when: IGDServiceAvailable do: [:IGDService |
IGDConfigurator configure: IGDService to: [:configurator |
configurator ppp
natEnabled: true;
addPortMapping: srcPort to: dstPort on: targetMachine
]
Where IGDConfigurator / ppp  is the missing piece, building/sending SOAP 
messages* to the provided service, corresponding to
http://upnp.org/specs/gw/UPnP-gw-WANPPPConnection-v1-Service.pdf

Cheers,
Henry

* the core (messaging parts of 
http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf) of which can 
probably be abstracted into a UPnPConfigurator, so all you do in IGD is link 
the API to which fields to send in the soap messages

> On 26 Jul 2016, at 4:19 , Norbert Hartl <norb...@hartl.name> wrote:
> 
> Thanks,
> 
> I think I need to read a bit further in order to understand how it works 
> really. Didn't know SSDP ist used when tweaking things with IGD.
> 
> Norbert
> 
>> Am 25.07.2016 um 17:01 schrieb Henrik Johansen 
>> <henrik.s.johan...@veloxit.no>:
>> 
>> SSDP covers discovery of the services and how they are set up; SOAP and XML 
>> are then used to access the service.
>> IANAE, but; I think as long as you restrict yourself to implement use of the 
>> particular service (IGD) you are interested in, it shouldn't be all that bad;
>> the use of SSDP discovery data should be fairly straigh forward the way its 
>> modelled; you provide the client with callbacks that run when a service of 
>> the type you've specified you're interested in becomes available/unavailable.
>> 
>> The main problem with UPnP (well, other than accessing services involving 
>> SOAP and XML instead of REST) is its size; a callback handling "IGD service 
>> discovered" should be much simpler than if one wanted to handle "UPnP device 
>> discovered" (or, if that's the pattern, restricting UPnP device discovery 
>> handling to check if IGD is available).
>> 
>> (You might want a separate Service subclass to ease access / document what 
>> the different fields are though, IIRC, the current Service follows the 
>> MorphicExtension pattern of putting anything that does not have a 
>> well-defined meaning in SSDP in a dictionary)
>> 
>> Cheers,
>> Henry
>> 
>>> On 25 Jul 2016, at 3:29 , Norbert Hartl <norb...@hartl.name> wrote:
>>> 
>>> Thanks,
>>> 
>>> am I wrong in assuming the UPnP and IGD are rather huge and complicated 
>>> things to implement? I just want to figure out if there is a clear answer 
>>> to the question if implementing a subset or using a library (mini upnp) 
>>> through FFI is more feasible.
>>> 
>>> Norbert
>>>> Am 25.07.2016 um 16:10 schrieb Henrik Johansen 
>>>> <henrik.s.johan...@veloxit.no>:
>>>> 
>>>> 
>>>>> On 25 Jul 2016, at 12:13 , Norbert Hartl <norb...@hartl.name> wrote:
>>>>> 
>>>>> Does anyone know some code or person that did something with UPnP/IGD in 
>>>>> pharo?
>>>>> 
>>>>> thanks,
>>>>> 
>>>>> Norbert
>>>> 
>>>> 
>>>> I've done an SSDP client/server, but not gone so far as to build a full 
>>>> UPnP model on top of it, since I just needed a discovery protocol.
>>>> http://smalltalkhub.com/#!/~henriksp/SSDP.
>>>> 
>>>> Should be possible to use as a base though; you can make a client with 
>>>> type ssdp:all, and get some fun replies indicating the services available 
>>>> on UPnP routers.
>>>> 
>>>> Caveats apply to the socket init code which is really ugly, it attempts to 
>>>> listen on all the interfaces present at the time of client creation, but 
>>>> the correct primitives aren't really exposed from the plugin, the results 
>>>> can be a bit hit and miss depending on OS/Distribution; nor are there 
>>>> hooks to get notified when interfaces go up/down, so accounting for such 
>>>> currently comes down to manual resets.
>>>> 
>>>> Cheers,
>>>> Henry
>>> 
>>> 
>> 
> 
> 



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] UPnP/IGD implementation

2016-07-25 Thread Henrik Johansen

> On 25 Jul 2016, at 12:13 , Norbert Hartl  wrote:
> 
> Does anyone know some code or person that did something with UPnP/IGD in 
> pharo?
> 
> thanks,
> 
> Norbert


I've done an SSDP client/server, but not gone so far as to build a full UPnP 
model on top of it, since I just needed a discovery protocol.
http://smalltalkhub.com/#!/~henriksp/SSDP.

Should be possible to use as a base though; you can make a client with type 
ssdp:all, and get some fun replies indicating the services available on UPnP 
routers.

Caveats apply to the socket init code which is really ugly, it attempts to 
listen on all the interfaces present at the time of client creation, but the 
correct primitives aren't really exposed from the plugin, the results can be a 
bit hit and miss depending on OS/Distribution; nor are there hooks to get 
notified when interfaces go up/down, so accounting for such currently comes 
down to manual resets.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] [Raspberry Pi] Accessing GPIO pins on Raspberry Pi?

2016-06-14 Thread Henrik Johansen
There doesn't seem to be many Pharoisms in WiringPi; for a much snappier 
experience, you might want to check out Squeak instead.
Raspbian ships with both Spur and Non-Spur VM's included (courtesy of Scratch) 
which include optimized BitBlt primitives (may be absent from the old Pharo VM) 
+ it uses bitmap fonts and has less configurable, but faster tools.

Since WiringPi uses FFI though, you'd have to find and load that manually 
before the actual WiringPi package, no metacello config for squeak afaict.

Cheers,
Henry

> On 14 Jun 2016, at 1:42 , Steven Costiou  wrote:
> 
> My bad, the leds were not on the right pins. Now all my leds are off and my 
> wiring is ok. It still doesn't work, but i'm not sure whether my setup is 
> wrong or if it just doesn't work anymore on Pharo5.
> 
> I will attempt to use the library outside Pharo, reconfigure a Pharo image & 
> vm and then try it again.
> 
> In the meantime if anyone does success at this, please let me know i am very 
> interested by using the GPIO pins from Pharo.
> 
> Steven.
> 
> 
> Le 2016-06-13 17:10, Steven Costiou a écrit :
> 
>> Hi,
>> 
>> i have tried to make it work but so far i can't get it right. Have you been 
>> able to work with it ?
>> 
>> I used pharo 5 latest non spur image with the non spur vm. It works on a 
>> raspberry 3 but it is very slow. I tried the led examples, the leds do not 
>> seem to be affected (some are on, some off, with a variable intensity).
>> 
>> 
>> Is there any specific settings needed for this to work ?
>> 
>> Thanks,
>> 
>> Steven.
>> 
>> 
>> Le 2016-05-27 20:11, sergio ruiz a écrit :
>> 
>> does anyone know if if pharo 5 runs on raspberry pi yet?
>> 
>> if so, i can poke around and see if i can get WiringPi to install on pharo 5.
>> 
>> thanks!
>> 
>> 
>> On May 27, 2016, at 1:56 PM, sergio ruiz > > wrote:
>> 
>> 
>> The raspberry pi slave seems to be disconnected so do not know the
>> status:
>> Library:
>> https://ci.inria.fr/pharo-contribution/job/WiringPi-ARM-AutomatedBuild/ 
>> 
>> Pharo code ( probably on Pharo 3 or 4).
>> http://smalltalkhub.com/#!/~jeanbaptistearnaud/WiringPi 
>> 
>> great! i'll take a look at those!
>> 
>> thanks!
>> 
>> 
>> peace,
>> sergio
>> photographer, journalist, visionary
>> #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
>> http://www.Village-Buzz.com 
>> http://www.ThoseOptimizeGuys.com 
>> http://www.CodingForHire.com 
>> http://www.coffee-black.com 
>> http://www.painlessfrugality.com 
>> http://www.twitter.com/sergio_101 
>> http://www.facebook.com/sergio101 
>> 
>> peace,
>> sergio
>> photographer, journalist, visionary
>> #BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
>> http://www.Village-Buzz.com 
>> http://www.ThoseOptimizeGuys.com 
>> http://www.CodingForHire.com 
>> http://www.coffee-black.com 
>> http://www.painlessfrugality.com 
>> http://www.twitter.com/sergio_101 
>> http://www.facebook.com/sergio101 
>> 
> --
> kloum.io



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo-BSON OID LargePositiveInteger increase

2016-05-31 Thread Henrik Johansen

> On 31 May 2016, at 11:44 , Holger Freyther  wrote:
> 
> not with Pharo5:
> 
> ((LargePositiveInteger new: 3) digitAdd: SmallInteger maxVal - 10) class
> => SmallInteger

That's a very recent change to the LargeInteger primitives, wasn't in my old 
spur vm (a month old perhaps).
So,in addition to #digitAdd: being 3 times slower than #+ (...jittability? 
Shouldn't be *that* much more work to add a byte to another byte compared to 
whatever #+ does)
nor is it hitting the fast path for replaceFrom:.. (2 variableX instances) 
either, meaning it'll see an even bigger improvement from reverting compared to 
Pharo4 (which got 50% faster...)

> '
> 
> cool! Change looks good but please remove the obsolete >>#digitAdd: comment.
> 
> thanks a lot!!

Done, published as .47
Tested counter increments and reset at image startup, seemed to work at least.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo-BSON OID LargePositiveInteger increase

2016-05-30 Thread Henrik Johansen

> On 30 May 2016, at 5:49 , Henrik Johansen <henrik.s.johan...@veloxit.no> 
> wrote:
> 
> A few more comments below; I'm not seeing the things you describe when 
> testing in my image...
> 
>>> 
>>> | id |
>>> id := LargePositiveInteger.
>>> 1 to: (16777215 + 50) do: [:each |
>>> id := id digitAdd: 1].
>>> id.
>>> 
>>> Given the comment it should overflow and the value be 50? This is not what 
>>> the result is. So shall the truncation be added again or at least the 
>>> comment be updated? The code will go from LargePositiveInteger to 
>>> SmallInteger when overflowing from three to four bytes
> 
> On which VM does it overflow to SmallInteger? I've never seen this, on the 
> one I tested the expression in last mail, the "overflowing" digitAdd: 
> returned a 4-byte LargePositiveInteger.

It's starting to come back to me; IIRC, + will normalize results to 
SmallIntegers, digitAdd: will not.

I thought it would be nice to use a single
replaceFrom:to:with:startingAt:
call to insert the entire counter; however, I didn't bench that particular part.

So while the rewrite overall gained a small amount of speed, it turns out 
digitAdd: is quite slow (even though it's a primitive), so reverting to using 
Smallinteger arithmetic for the counter, and inserting the counter a digit at a 
time is most likely worth it:

"Pharo4, LargeInteger counter"
[OID new] bench '1,194,004 per second'

"Pharo4, reverted to SmallInteger counter"
[OID new] bench '1,681,203 per second'

The relevant changes should be present in attachment.

Cheers,
Henry



OIDrevertCounter.cs
Description: Binary data






signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo-BSON OID LargePositiveInteger increase

2016-05-30 Thread Henrik Johansen

> On 30 May 2016, at 5:49 , Henrik Johansen <henrik.s.johan...@veloxit.no> 
> wrote:
>>> 
>>> PS: The other part is that >>#newCounter doesn't seem to be ever executed. 
>>> On first load >>#initialize will call >>#reset and on >>#shutDown: calls 
>>> reset. So the code to "randomize" the initial counter doesn't seem to work.
> 
> What?
> OID class >> #initialize adds the class to the shutdown list, so it *should* 
> call shutDown: whenever the image is saved
> newCounter should then be called on first request after startup, since 
> machineIdentifier is set to nil by reset.


/doh, I see it now.
reset should do

counter := nil, not
counter := LargePositiveInteger new: 3 .

PEBKAC when rewriting the old

counter := 0

reset code, I'm afraid :/


Cheers,
Henry



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo-BSON OID LargePositiveInteger increase

2016-05-30 Thread Henrik Johansen
A few more comments below; I'm not seeing the things you describe when testing 
in my image...

>> 
>> | id |
>> id := LargePositiveInteger.
>> 1 to: (16777215 + 50) do: [:each |
>>  id := id digitAdd: 1].
>> id.
>> 
>> Given the comment it should overflow and the value be 50? This is not what 
>> the result is. So shall the truncation be added again or at least the 
>> comment be updated? The code will go from LargePositiveInteger to 
>> SmallInteger when overflowing from three to four bytes

On which VM does it overflow to SmallInteger? I've never seen this, on the one 
I tested the expression in last mail, the "overflowing" digitAdd: returned a 
4-byte LargePositiveInteger.


>> but luckily
>> 
 #value
>>  ...
>>  replaceFrom: 1 to: 3with: self class counterNext startingAt: 1
>> 
>> will even work when counterNext returns a SmallInteger. But given the old 
>> code and the comment in the new code this is does not seem to function as 
>> intended?
>> 

Are you sure?
On my VM,
(ByteArray new: 3) replaceFrom: 1 to: 3 with: 16r1FF startingAt: 1
gives an "Instances of SmallInteger are not indexable" error...

>> 
>> 
>> PS: The other part is that >>#newCounter doesn't seem to be ever executed. 
>> On first load >>#initialize will call >>#reset and on >>#shutDown: calls 
>> reset. So the code to "randomize" the initial counter doesn't seem to work.

What?
OID class >> #initialize adds the class to the shutdown list, so it *should* 
call shutDown: whenever the image is saved
newCounter should then be called on first request after startup, since 
machineIdentifier is set to nil by reset.

Cheers,
Henry





signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] [Article] Speeding up factorial computation by changing the order of multiplications

2016-05-24 Thread Henrik Johansen
For the specially interested, there's also this fun thread from some years ago:
http://forum.world.st/Challenge-Tuning-the-large-factorial-td3588660.html 


Cheers,
Henry

> On 24 May 2016, at 9:57 , Sven Van Caekenberghe  wrote:
> 
> I just published a short, introduction level article,
> 
> Speeding up factorial computation by changing the order of multiplications.
> 
> This is a story about a small, seemingly innocent code change that speeds up 
> a very simple computation. It is pretty magical and serves as an example of 
> how things are not always what they seem.
> 
> https://medium.com/concerning-pharo/speeding-up-factorial-computation-by-changing-the-order-of-multiplications-f4da3a5576da#.l3nrk9oax
> 
> Enjoy,
> 
> Sven
> 
> --
> Sven Van Caekenberghe
> Proudly supporting Pharo
> http://pharo.org
> http://association.pharo.org
> http://consortium.pharo.org
> 
> 
> 
> 
> 



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] [ARTICLE] Tiny, yet so beautiful

2016-03-10 Thread Henrik Johansen

> On 10 Mar 2016, at 3:01 , Peter Uhnák  wrote:
> 
> "Nice article. But asBit has existed in @SqueakSmalltalk since at least 2004. 
> Why not say so?"
> https://twitter.com/bertfreudenberg/status/707922868273856512 
> 
> 
> And indeed, in Pharo I see it added on 27.3. and 28.12.2012 (why almost a 
> year difference?)
> 
> And in Squeak I see it added 1.7.2004 (although they don't have it in Boolean 
> class).
> 
> The rest of the Boolean class looks pretty identical to the letter (including 
> comments), so it makes one wonder why wasn't this copied over.
> 
> Peter

It was, the same version of asBit you find in Squeak was present in Pharo 1.4 
and earlier.
Though, uncategorized, and without the subclassResponsibility implementation on 
Boolean.

2.0 development was hectic, hard to tell if it was cleaned away and then 
re-added/invented ( I think it may have, I seem to remember it being an 
extension in NB for awhile)
The source compaction that happened at 2.0 release removed any lingering traces 
of the old version, either way attributing Anthony Hannan as well wouldn't be 
entirely out of place.

Either way, a beautiful bit of code!

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Use cases for methods with optional parameters

2016-01-21 Thread Henrik Johansen

> On 20 Jan 2016, at 6:14 , Esteban A. Maringolo  wrote:
> 
> 
> I would be interested in the use cases and how to deal with
> "undefined" arguments, will they be nil or other kind of undefined
> object?
> 
> Regards!
> 
> Esteban A. Maringolo

Perhaps

request: aFile with: anotherThing and: aThirdThing


->
request: aFile with: anotherThing
^self request: aFile with: anotherThing and: self defaultThirdThing
request: aFile and:: aThirdThing
^self request: aFile with: nil and: self aThirdThing
request: aFile
^self request: aFile with: nil and: self defaultThirdThing

?

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Slow object printOn: with EURO symbol

2016-01-05 Thread Henrik Johansen

> On 05 Jan 2016, at 3:20 , Hilaire  wrote:
> 
> Le 05/01/2016 14:38, Sven Van Caekenberghe a écrit :
>> The problem can does also be restated: it is really necessary for a tool to 
>> convert 1000s of items to strings, even if only 10s are shown at the same 
>> time on a screen ?
>> 
>> I believe that fast table tries to do better here.
> But I need to show 1000s of them once, all in the same view, at the same
> time.
> 
> Hilaire

I think Sven was referring to opening an inspector, where you usually only see 
10-20 items in a list at once, even if the total number of items is much larger.
The new FastTable/List/Tree/WhateverItsCalled are much better suited for this, 
instead of creating the 1500 Strings that can potentially be shown before even 
opening the inspector, it creates the 20 or so that will actually be shown, 
then generates the rest as you scroll.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Slow object printOn: with EURO symbol

2016-01-04 Thread Henrik Johansen

> On 02 Jan 2016, at 10:58 , Hilaire  wrote:
> 
> Hello,
> 
> With Pharo3, in an object of mine, I want its text representation to
> come with the EURO symbol:
> 
> CGMoney>>printOn: aStream
>   aStream << (amount asScaledDecimal: 2) greaseString
>   << ' ' << '€'
> 
> 
> It appears to be very slow when I browse such collection of objects
> (says 1500) from an inspector
> 
> Replacing '€' by 'EUR' gives back normal rendering time.
> 
> Indeed the '€' is encoded as WideString, so not sure what is happening.
> All content converted to WideString or what?


In the fallback code for WriteStream >> #nextPut:, at:put: is called,  so yes, 
streaming a wide char causes the streams collection to be converted from Byte 
to WideString.
Conversion is done using become, which currently triggers a full heap scan for 
references, and is thus very slow.
One could add a fast-path along the lines of #pastEndPut: (which has already 
broken any assumption that a reference to the collection will reflect all 
writes for the lifetime of stream, for the same performance problems one would 
face using #become:); if collection is a ByteString and anObject is a wide 
characters, replace collection with a WideString, and *then* call at:put:
But, it is not a very nice thing to add to a generic streaming class, nor is it 
a very attractive at this point in time considering that making become: a fast 
operation is one of the problems solved by Spur.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo configuration for Pharo40

2015-12-04 Thread Henrik Johansen

> On 04 Dec 2015, at 3:49 , Esteban Lorenzano  wrote:
> 
> Yes I think… I still do not update voyage to Pharo5 (there are not TimeStamps 
> anymore).
> 
> Esteban
> 
>> On 04 Dec 2015, at 15:43, stepharo  wrote:
>> 
>> Does it make sense to have
>> 
>>  Name: ConfigurationOfVoyageMongo-EstebanLorenzano.38
>> Author: EstebanLorenzano
>> Time: 9 May 2015, 8:40:27.23963 am
>> UUID: 9ba71817-b3f9-4f66-8579-e09e5deb5935
>> Ancestors: ConfigurationOfVoyageMongo-EstebanLorenzano.37
>> 
>> fixed a problem with the versionner tool
>> 
>> in the Catalog for Pharo 40?
>> 
>> Stef
>> 
> 
> 

I found this to be kind of a big deal when trying to remove deprecations in 
4.0, as TimeStamps and DateAndTime are mapped to different BSON classes...
If you change Documents to use DateAndTime now instead of Timestamp now, and 
write them to a legacy database, they will save just fine, but Mongo will give 
errors if you try to sort documents by that field due to incompatible types. :/

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo configuration for Pharo40

2015-12-04 Thread Henrik Johansen

> On 04 Dec 2015, at 5:22 , Sven Van Caekenberghe  wrote:
> 
> According to http://bsonspec.org/spec.html there are indeed 2 different types
> 
> "\x09" e_name int64   UTC datetime
> 
> "\x11" e_name int64   Timestamp
> 
> I would guess that you need 2 different (sub)classes in Pharo if you want to 
> honour this spec. It has little to do with the almost empty TimeStamp 
> subclass of DateAndTime having been removed. This is an API design issue 
> (decide on the Pharo to BSON type mapping).

Strictly speaking, Timestamp should've never been mapped;
 "Timestamp - Special internal type used by MongoDB replication and sharding. 
First 4 bytes are an increment, second 4 are a timestamp"
doesn't exactly agree with the smalltalk implementation:
nextTimestampPut: aTimestamp
self nextDateAndTimePut: aTimestamp

It's a problem when an existing application stored Timestamp instances with the 
broken type, for the reason I explained.
I'd be fine with having a legacy-compatibility package containing Timestamp 
class + bson extensions as before (even though it was broken) strictly for use 
when migrating legacy applications.

That's what we have Monticello groups for, right? ;)

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Mongo configuration for Pharo40

2015-12-04 Thread Henrik Johansen

> On 04 Dec 2015, at 5:41 , Henrik Johansen <henrik.s.johan...@veloxit.no> 
> wrote:
> 
> 
> That's what we have Monticello groups for, right? ;)
> 

I meant to write *Metacello* groups, obviously...

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] typers in Pharo

2015-11-16 Thread Henrik Johansen
I don't know why, but return typing seems explicitly disabled in Pharo for 
RoelTyper.

Add the extraction in:
PharoInstVarInterfaceExtractor >> #methodReturnTop
collector addAssignmentForReturn: stack last.
^self pop

and it seems to work for me at least.


The dictionary access failure is a bug in packagedResultsForCompiledMethod: , 
since the results are kept in an IdentityDictionary, we need to use as keys 
symbols, not strings, if we later want to fetch them using literals:

packagedResultsForCompiledMethod: aCompiledMethod
| results arr tmpNames|
results := IdentityDictionary new.
arr := (localTypingResults at: aCompiledMethod).
tmpNames := [aCompiledMethod methodNode tempNames] on: Error do: 
[aCompiledMethod tempNames].
1 to: arr size - 1 do: [:i | results at: (tmpNames at: i) put: 
(arr at: i)].
results at: #'^' put: (arr last).
^results

Cheers,
Henry

> On 15 Nov 2015, at 11:16 , Peter Uhnák  wrote:
> 
> Hi,
> 
> apparently neither RoelTyper nor RefactoryTyper is capable of doing 
> elementary type inference for methods, such as
> 
> [[[
> cls := Object subclass: #Something.
> cls compile: 'method ^ 1'.
> typer := RBRefactoryTyper new.
> typer guessTypeFromAssignment: (Something>>#method) ast body "Object
> "
> all := (TypeCollector typeTmpsIn: (Something>>#method) ofClass: Something) 
> asDictionary.
> (all at: '^') types "an OrderedCollection(Object)"
> ]]]
> 
> Of course both of those tools have different objectives so I am not surprised.
> 
> Are there however other options? Roel Typer paper makes mention of Chuck, but 
> that seems to be for Squeak only.
> 
> As for RoelTyper I've also encountered very strange behavior:
> [[[
> cls := Object subclass: #Something.
> cls compile: 'method ^ 1'.
> all := TypeCollector typeTmpsIn: (Something>>#method) ofClass: Something.
> 
> all at: '^' ifAbsent: [ 'Not Found' ]. "'Not Found'"
> 
> all asDictionary at: '^' "ExtractedType: Sends: {}
> Assignments: {}
> ".
> 
> all associations detect: [ :pair | pair key = '^' ] "'^'->ExtractedType: 
> Sends: {}
> Assignments: {}
> "
> ]]]
> 
> Why does the first #at: fail if the second and especially third succeeds? My 
> debugging lead me to IdentityDictionary>>#scanFor: but I don't know why that 
> method is written in such a way so I stopped there.
> 
> Thanks,
> Peter



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Changing playground and monticello shortcuts

2015-11-11 Thread Henrik Johansen
Ehm, or maybe fix event dispatch so it works properly?
It should always end up testing for event handling By the leaf morph at the 
given event position and work its way up if unhandled, not check top-down like 
the change to dispatchEvent:with: has ended up doing...

Cheers,
Henry

> On 11 Nov 2015, at 11:46 , Tudor Girba  wrote:
> 
> I actually think we should disable those shortcuts.
> 
> The reason is that they “pollute" the global shortcut space: for example, you 
> can now not use Cmd+o for any custom action in your own window, and that is 
> less than ideal.
> 
> The alternative is to use Spotter to spawn windows. The interesting thing 
> there is that you do not need shortcuts for every specific windows because 
> you can use regular search. For example, opening Playground is: Shift+Enter, 
> p, Enter
> 
> Cheers,
> Doru
> 
> 
>> On Nov 11, 2015, at 10:49 AM, Nicolai Hess  wrote:
>> 
>> 
>> 
>> 2015-11-11 10:45 GMT+01:00 Peter Uhnák :
>> Hi,
>> 
>> currently to open a Playground via shortcut one has to type +o+w, 
>> that's because it used to open Workspace.
>> However since it now opens Playground the shortcut is no longer appropriate.
>> 
>> So can we change it to +o+p?
>> (This shortcut is currently occupied by Monticello Browser, but that can be 
>> movd to +o+m which is free.)
>> 
>> cmd+o+m would be
>> ctrl+o ctrl+m on windows, but ctrl+m does not work yet on windows.
>> 
>> 
>> You could argue that people are used to this shortcut, however that will not 
>> be true for newcommers, who will just see it as random naming (which it 
>> currently is).
>> 
>> Peter
>> 
> 
> --
> www.tudorgirba.com
> 
> "We cannot reach the flow of things unless we let go."
> 
> 
> 
> 



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Artefact and WideString

2015-10-22 Thread Henrik Johansen

> On 22 Oct 2015, at 3:31 , Sabine Manaa  wrote:
> 
> I do also use two different implementations for artefact/pdf and html:
> 
> artefact:
> 128 asCharacter asString
> 
> html:
> '€'
> 
> same would be great

https://www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf 

4.9 character
"character numeric code representing an abstract symbol according to some 
defined character encoding rule
NOTE 1 There are three manifestations of characters in PDF, depending on 
context:
• A PDF file is represented as a sequence of 8-bit bytes, some of which are 
interpreted as character codes in the ASCII character set and some of which are 
treated as arbitrary binary data depending upon the context.
• The contents (data) of a string or stream object in some contexts are 
interpreted as character codes in the PDFDocEncoding or UTF-16 character set.
• The contents of a string within a PDF content stream in some situations are 
interpreted as character codes that select glyphs to be drawn on the page 
according to a character encoding that is associated with the text font. "

What those contexts are, I don't know, but they all need to be handled 
differently;
- For bullet one, there's nothing to do.
- For bullet 2, there needs to be an encoding layer which converts the strings 
to proper format when writing the PDF, see section 7.9.2.
Seems to me the process would be simpler when writing the file if one ignored 
PDFDocEncoding altogether and eiter write ascii, or convert to BOM-marked UTF16 
(in the same way we write ASCII or BOM-marked UTF8 for chunk files)
- For bullet 3, one would need to convert to the fonts character set.

Cheers
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Better Code Completion

2015-10-06 Thread Henrik Johansen

> On 06 Oct 2015, at 1:33 , Nicolai Hess  wrote:
> 
> 
> 
> 2015-10-06 11:57 GMT+02:00 Werner Kassens  >:
> On 10/06/2015 09:09 AM, Nicolai Hess wrote:
>  > Since Object has almost 500 methods whatever I will start typing
> Object/TClass/TBehavior/... will have a list of answers...
> 
> I think this is difficult, even though this classes are big and you
> don't use most of the methods,
> 
> 
> Hi Nicolai,
> imagine that code-completion is a game and the computer wins, if the user 
> mostly uses the first few proposals. perhaps one could program several 
> different heuristics, that decide, what the user wants. depending on the user 
> choices, the weights for these heuristics get updated accordingly and then 
> the choices get sorted with those weights. this way the code-completion could 
> adapt to the way each user works?
> 
> 
> Yes this would be nice, but it is not an easy task.
> 
> werner
> 
> 

I thought we already had something like that...
http://www.squeaksource.com/OCompletion/

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] issue with large file path on windows

2015-08-24 Thread Henrik Johansen

 On 23 Aug 2015, at 6:09 , Nicolai Hess nicolaih...@web.de wrote:
 
 And If you want to review the changes:
 
 https://github.com/nicolaihess/pharo-vm/compare/master...nicolaihess:win-long-filename
  
 https://github.com/nicolaihess/pharo-vm/compare/master...nicolaihess:win-long-filename
 
 
 2015-08-23 13:44 GMT+02:00 Nicolai Hess nicolaih...@web.de 
 mailto:nicolaih...@web.de:
 For those who had problems with pharo on windows and github based 
 repositories,
 I built a windows vm with support for long paths:
 
 https://drive.google.com/file/d/0B8yEahnuIem2bmxwdzJuUXFxVGM/view?usp=sharing 
 https://drive.google.com/file/d/0B8yEahnuIem2bmxwdzJuUXFxVGM/view?usp=sharing
 
 
 For browsing directories with large paths (FileList or Inspect),
 you may need one additional change in the image (But I am not really sure 
 about that) :
 
 DiskStoreinitialize
 super initialize.
 maxFileNameLength := Smalltalk vm maxFilenameLength ifNil: [ 32767 ].
 
 
 please test and give feedback.
 
 This wasn't as easy as I thought, and I had to make some more changes
 for the file permissions (the stat-functions don't work for files with long 
 paths).
 Please test other file/folder operations.
 
 
 nicolai
 
 
 
 

+  #define CONVERT_MULTIBYTE_TO_WIDECHAR_PATH(buffer, size, fileNameString, 
fileNameLength)  {  \
+buffer = (WCHAR*)alloca((size+4+1)*sizeof(WCHAR));\
+buffer[0] = L'\\';buffer[1] = L'\\'; buffer[2] = L'?'; buffer[3] = L'\\';\
+MultiByteToWideChar(CP_UTF8, 0, fileNameString, fileNameLength, buffer + 
4, size);\
+buffer[size + 4] = 0;\
+size += 4;}


- Is an alloca version really worth it for the potential problems?
- Also, LONG_PATH_PREFIX_SIZE is defined above in the header, should probably 
use this instead of 4 in the last two lines?
- The comment on lines 111/164/265/381, while not modified, are somewhat 
incorrect, null-terminated C-string indicates UTF8, which we are converting 
from, not into.

I'm curious what the \\?\ smb://?/ prefix does to hasCaseSensitiveDuplicate 
(adding a new ? segment to the path), but I cba to understand that code, and 
considering
int caseSensitiveFileMode = 0;
if(!caseSensitiveFileMode) return 0;

I guess it doesn't really matter.

Otherwise, looks good to me!

Cheers,
Henry

Re: [Pharo-users] Font with many Unicode glyphs to display code -- IPA?

2015-07-24 Thread Henrik Johansen

 On 23 Jul 2015, at 4:14 , H. Hirzel hannes.hir...@gmail.com wrote:
 
 P.S. Screen shot attached.
 A source code font.
 Or put the question differently how do I add a font as a source code font?
 
 
 On 7/23/15, H. Hirzel hannes.hir...@gmail.com wrote:
 Hello
 
 I work on an app which has some strings in the code with a
 considerable number of non ISO8859 symbols (e.g. IPA
 https://en.wikipedia.org/wiki/IPA)
 
 How do I get / use a font which does this? The fonts provided in the
 settings panel did not do the job.
 
 Thank you in advance
 --Hannes
 
 Pharo4.0_settings_browser_fonts_Screenshot from 2015-07-23 13:58:28.png

Click the font name next to the Code entry to change it, press Update in the 
selection window, and then select a system font (after installing if it's not 
included in the OS) that has IPA coverage.
Searching for ipa font my platform should give pointers to which you can 
use.

Cheers,
Herny


Re: [Pharo-users] adding an element to an empty array

2015-06-29 Thread Henrik Johansen

 On 29 Jun 2015, at 2:18 , abdelghani ALIDRA alidran...@yahoo.fr wrote:
 
 Hi guys,
 
 Is there any way to add an element to an empty array (must not use new: 
 anElement)?
 
 Cheers

It sounds like you want to use an OrderedCollection, not an Array.
Those will grow and shrink as needed when you use add:/remove: calls.

Cheers,
Henry

Re: [Pharo-users] ZnClient and percent characters

2015-06-11 Thread Henrik Johansen

 On 11 Jun 2015, at 9:51 , PBKResearch pe...@pbkresearch.co.uk wrote:
 
 I don’t quite understand Norbert’s comment. Does ‘monkey’ apply to me or to 
 what I have done? Either way, it seems unnecessary and abusive. 

It's a phrase to describe the change: http://en.wikipedia.org/wiki/Monkey_patch 
http://en.wikipedia.org/wiki/Monkey_patch
I think Ruby popularized it, the phrase I was familiar with in a Smalltalk 
context was method override

 Thanks to Sven’s careful use of informative method names, the effect of my 
 change is quite clear. Any comma in the value part of a query line will be 
 encoded. Nothing else. I did my best to trace any side effects, and didn’t 
 find any. What is not ‘reliable’ about that?
  
 Peter Kenny

The problem with overrides of methods in an external librarey arise when:
- Other packages you load depend on the same method being monkey patched in a 
different way way.
- Bug fixes/Refactorings in the base library renders the change 
incorrect/obsolete, which can be hard to notice. *

Subclassing and adding your modifications there instead solves the first 
problem.
Reading the specs, determining the original behaviour is a bug, submitting a 
fix, and have it accepted in the base library instead fixes both.

Cheers,
Henry

* For instance, in my day job maintaining a VW application, when upgrading to 
new versions, verifying that all monkey patches are still correct accounts for 
a significant portion of the time spent

Re: [Pharo-users] NativeBoost pointer and +

2015-06-09 Thread Henrik Johansen
There are many ways to Rome :)
If you just need some externally allocated objects in the formats you specified 
you can do the cache extraction using nothing but normal Smalltalk:

intArray := (NBExternalArray ofType: 'int').

data := intArray new: 1000.
1 to:data size do:[:i |data at:i put: i].
cache := intArray new: 50.
0 to: 4 do: [:j | 
1 to: 10 do: [ :k |
cache at: (j* 10) + k put: (data at: 199 + (30 * j ) + k)] ].

But if you want to take full advantage of the performance boost NB offers, 
you'd write a NativeBoost function to do the cache extraction*, as I outlined 
last time:
MyClass class  #createCacheOf: aSource in: aDestination
createCacheOf: aSource in: aDestination
primitive: #primitiveNativeCall module: #NativeBoostPlugin
Should work on both x86 and x64, as long as sizeOf: lookups work 
correctly
^ self nbCallout 
function: #(void (int * aSource, int * aDestination) ) 
emit: [:gen :proxy :asm | |destReg srcReg tmpReg intSize 
ptrSize|
intSize := NBExternalType sizeOf: 'int'.
ptrSize := NBExternalType sizeOf: 'void *'.
Only use caller-saved regs, no preservation needed
destReg := asm EAX as: ptrSize.
srcReg := asm ECX as: ptrSize.
tmpReg := asm EDX as: intSize.
asm pop: srcReg.
asm pop: destReg.
0 to: 4 do: [ :j | 0 to: 9 do: [ :offset |
asm 
Displacement in bytes, not ptr element 
size :S, so we have to multiply offset by that manually :S
mov: tmpReg with: srcReg ptr + (199 + 
(j * 30) + offset * intSize);
mov: destReg ptr  + ((j* 10) + offset * 
intSize) with: tmpReg]]]  

and use that;
intArray := (NBExternalArray ofType: 'int').
data := intArray new: 1000. 
1 to:data size do:[:i |data at:i put: i].
cache := intArray new: 50.
MyClass createCacheOf: data in: cache.

The difference using a simple [] bench is about two orders of magnitude; 
11million cache extractions per seconds for the inline assembly version, while 
the naive loop achieves around 110k.

Cheers,
Henry

*as: is not yet defined, could be something like:
AJx86GPRegister  #as: aSize
^ self isHighByte
ifTrue: [ self asLowByte as: aSize ]
ifFalse: [ 
AJx86Registers
generalPurposeWithIndex: self index
size: aSize
requiresRex: self index  (aSize  1 ifTrue: 
[7] ifFalse: [ 3])
prohibitsRex: false ]


 On 09 Jun 2015, at 9:46 , Matthieu Lacaton matthieu.laca...@gmail.com wrote:
 
 Hello Henrik,
 
 Thank you very much for your answer. However, the code you provided is some 
 sort of assembly right ? So does it mean that I need to learn assembly to do 
 what I want ?
 
 I'm asking that because I don't know anything about assembly so it will take 
 me some time to learn.
 
 Cheers, 
 
 Matthieu
 
 2015-06-08 19:56 GMT+02:00 Henrik Johansen henrik.s.johan...@veloxit.no 
 mailto:henrik.s.johan...@veloxit.no:
 
  On 08 Jun 2015, at 4:41 , Matthieu Lacaton matthieu.laca...@gmail.com 
  mailto:matthieu.laca...@gmail.com wrote:
 
  Hello everyone,
 
  I have a small question about NativeBoost : How does the + operator when 
  applied to a pointer translates into NativeBoost code ?
 
  To give a bit of context, what I want to do is to reallocate some 
  non-contiguous bytes in memory to a buffer. Basically, I have an array of 
  integers in a buffer and I want to copy some chunks of it in another 
  buffer. The chunks are always the same size and the offset between each 
  chunk is always the same too.
 
  Because a bit of actual code is easier to understand here is what I'd like 
  to do in Pharo :
 
  ...
 
  int i, j;
  int *data = malloc(1000*sizeof(int));
  int *newData = malloc(50*sizeof(int));
 
  // Allocate initial data
  for (i = 0 ; i  1000, i++) {
data[i] = i;
  }
 
  //Copy desired chunks into new buffer
  for (i = 0; i  5; i++ ) {
memcpy( newData + j*10, data + 200 + j*30, 10*sizeof(int));
j++;
  }
 
  free(data);
 
 
 
 You can do relative addressing like this:
 (destReg ptr: dataSize) + offsetReg + constant
 
 So with offSetRegs containing j* 10 and j* 30, you might end up with an 
 unrolled inner loop (barring using any fancier longer-than-int moves) like:
 
 0 to: 9 do: [:constantOffset |
 asm mov: (destReg ptr: currentPlatform sizeOfInt) + dstOffsetReg + 
 constantOffset  with: (srcReg ptr: currentPlatform sizeOfInt) + 200 + 
 srcOffsetReg + constantOffset]
 
 If the range of j is constant, you can just as easily unroll the whole thing 
 in a similarly compact fashion, space

Re: [Pharo-users] NativeBoost pointer and +

2015-06-09 Thread Henrik Johansen

 On 09 Jun 2015, at 2:59 , Henrik Johansen henrik.s.johan...@veloxit.no 
 wrote:
 
 MyClass createCacheOf: data in: cache.

Forgot to change this; you need to pass in the ExternalArray addresses as 
parameters, not the ExternalArrays themselves.

MyClass createCacheOf: data address in: cache address

Cheers,
Henry

Re: [Pharo-users] NativeBoost pointer and +

2015-06-08 Thread Henrik Johansen

 On 08 Jun 2015, at 4:41 , Matthieu Lacaton matthieu.laca...@gmail.com wrote:
 
 Hello everyone, 
 
 I have a small question about NativeBoost : How does the + operator when 
 applied to a pointer translates into NativeBoost code ?
 
 To give a bit of context, what I want to do is to reallocate some 
 non-contiguous bytes in memory to a buffer. Basically, I have an array of 
 integers in a buffer and I want to copy some chunks of it in another buffer. 
 The chunks are always the same size and the offset between each chunk is 
 always the same too.
 
 Because a bit of actual code is easier to understand here is what I'd like to 
 do in Pharo : 
 
 ...
 
 int i, j;
 int *data = malloc(1000*sizeof(int));
 int *newData = malloc(50*sizeof(int));
 
 // Allocate initial data
 for (i = 0 ; i  1000, i++) {
   data[i] = i;
 }
 
 //Copy desired chunks into new buffer
 for (i = 0; i  5; i++ ) {
   memcpy( newData + j*10, data + 200 + j*30, 10*sizeof(int));
   j++;
 }
 
 free(data);



You can do relative addressing like this:
(destReg ptr: dataSize) + offsetReg + constant

So with offSetRegs containing j* 10 and j* 30, you might end up with an 
unrolled inner loop (barring using any fancier longer-than-int moves) like:

0 to: 9 do: [:constantOffset | 
asm mov: (destReg ptr: currentPlatform sizeOfInt) + dstOffsetReg + 
constantOffset  with: (srcReg ptr: currentPlatform sizeOfInt) + 200 + 
srcOffsetReg + constantOffset]

If the range of j is constant, you can just as easily unroll the whole thing in 
a similarly compact fashion, space and sensibilites permitting:

0 to: 4 do: [ :j | 0 to: 9 do: [ :consOffset | 
asm mov: (destReg ptr: currentPlatform sizeOfInt) + (j* 10) + 
constOffset  with: (srcReg ptr: currentPlatform sizeOfInt) + 200 + (j * 30) + 
constOffset]

Cheers,
Henry


Re: [Pharo-users] Issue with UDP Sockets

2015-06-01 Thread Henrik Johansen

 On 29 May 2015, at 7:24 , Sven Van Caekenberghe s...@stfx.eu wrote:
 
 
 On 29 May 2015, at 18:23, Henrik Johansen henrik.s.johan...@veloxit.no 
 wrote:
 
 
 On 19 May 2015, at 11:01 , Sven Van Caekenberghe s...@stfx.eu wrote:
 
 
 On 19 May 2015, at 10:53, Udo Schneider udo.schnei...@homeaddress.de 
 wrote:
 
 Did you look in all your package caches ?
 I did. Must have been a victim of cleaning ... but maybe TimeMachine has 
 something ... thanks for the reminder.
 
 If it is just a small example, like one class, maybe it could be
 added to the image, in which case it should indeed be a slice.
 The package was pretty simple. Basically only adding a few convenience 
 methods around Socket#setOption:value: . Still I think a usage example 
 in form of a class comment and test case might be appropriate. So unless 
 Multicast should be part of the base image I'll start with a separate 
 package first.
 
 Since Socket is a fundamental part, and multicast is a key feature, I think 
 it would logical to move it to the image itself, with a test case.
 
 It's not just multicast...
 As a Socket newbie I recently spent longer than I care to admit learning you 
 need to set SO_BROADCAST to true to not get a primitive failure when sending 
 to a broadcast address. 
 At least the comments in sqUnixSocket were entertaining!
 
 Though I realize which options are actually supported depends on the VM, 
 moving the list of potentially available cross-platform options (and a 
 description of what they're used for) to a comment in the image (setOption: 
 value: being the obvious location) might be a nice first step. 
 
 Please help in the documentation effort.

I later found the option names are already documented in getOption:, but since 
that wasn't of much help (at least to me), I suggest introducing a more 
specific error than primitiveFailure.
Implementing that, the new test revealed a bug; empty UDP payloads will not be 
sent.

A suggested fix for both these issues can be found in 
SLICE-Issue-15657-Empty-UDP-packets-are-not-sent-HenrikSperreJohansen.1

Cheers,
Henry


Re: [Pharo-users] Issue with UDP Sockets

2015-05-18 Thread Henrik Johansen

 On 18 May 2015, at 4:44 , Sven Van Caekenberghe s...@stfx.eu wrote:
 
 
 On 18 May 2015, at 16:34, Manfred Kröhnert mkroehner...@googlemail.com 
 wrote:
 
 Hi Sven,
 
 On Mon, May 18, 2015 at 4:14 PM, Sven Van Caekenberghe s...@stfx.eu wrote:
 
 On 18 May 2015, at 15:47, Manfred Kröhnert mkroehner...@googlemail.com 
 wrote:
 
 Hi,
 apparently I am missing something else.
 
 I can find devices when connected to a 'regular' LAN.
 
 However, I have a camera that creates a Wifi accesspoint and makes itself 
 discoverable via SSDP.
 Once I connect to this accesspoint my computer gets a valid IP address 
 assigned and the NodeJS code is able to discover the device.
 Unfortunately, the Pharo snippet I posted before does not give me any 
 results and hangs in SocketwaitForDataIfClosed: .
 
 Any further ideas?
 
 Are you sure you restarted the image and your code after switching networks ?
 
 I did not check this before.
 But I just downloaded a fresh 40613 image with PharoLauncher and started it 
 after connecting to the camera accesspoint.
 The code snippet freezes there as well.
 
 Manfred

The socket API is a bit confusing, since it mixes together the API's that match 
the primitives for sending/receiving TCP/UDP.
To receive UDP data on the socket, you need something like:

| message udpSocket host buffer read|
  message := (String crlf join: #('M-SEARCH * HTTP/1.1'
'HOST:239.255.255.250:1900' 
'MAN:ssdp:discover' 
'ST:ssdp:all' 
'MX:1')).

  udpSocket := Socket newUDP.
  host :=  (NetNameResolver addressFromString: '239.255.255.250').
  udpSocket sendData: message toHost: host port: 1900.
buffer := String new:4096.
MX:1 means we expect replies within 1 second, let's be on the safe side and 
wait 2
2 seconds wait.
read := 1.
[read  0] whileTrue: [
read := (udpSocket receiveUDPDataInto: buffer) first.
Transcript show: (buffer copyFrom:1 to:read)]

Cheers,
Henry


Re: [Pharo-users] Issue with UDP Sockets

2015-05-18 Thread Henrik Johansen
Hupps, was reading the old code, I guess this isn't applicable.
Sorry :/

 On 18 May 2015, at 5:15 , Henrik Johansen henrik.s.johan...@veloxit.no 
 wrote:
 
 
 On 18 May 2015, at 4:44 , Sven Van Caekenberghe s...@stfx.eu wrote:
 
 
 On 18 May 2015, at 16:34, Manfred Kröhnert mkroehner...@googlemail.com 
 wrote:
 
 Hi Sven,
 
 On Mon, May 18, 2015 at 4:14 PM, Sven Van Caekenberghe s...@stfx.eu wrote:
 
 On 18 May 2015, at 15:47, Manfred Kröhnert mkroehner...@googlemail.com 
 wrote:
 
 Hi,
 apparently I am missing something else.
 
 I can find devices when connected to a 'regular' LAN.
 
 However, I have a camera that creates a Wifi accesspoint and makes itself 
 discoverable via SSDP.
 Once I connect to this accesspoint my computer gets a valid IP address 
 assigned and the NodeJS code is able to discover the device.
 Unfortunately, the Pharo snippet I posted before does not give me any 
 results and hangs in SocketwaitForDataIfClosed: .
 
 Any further ideas?
 
 Are you sure you restarted the image and your code after switching networks 
 ?
 
 I did not check this before.
 But I just downloaded a fresh 40613 image with PharoLauncher and started it 
 after connecting to the camera accesspoint.
 The code snippet freezes there as well.
 
 Manfred
 
 The socket API is a bit confusing, since it mixes together the API's that 
 match the primitives for sending/receiving TCP/UDP.
 To receive UDP data on the socket, you need something like:
 
 | message udpSocket host buffer read|
  message := (String crlf join: #('M-SEARCH * HTTP/1.1'
'HOST:239.255.255.250:1900' 
'MAN:ssdp:discover' 
'ST:ssdp:all' 
'MX:1')).
 
  udpSocket := Socket newUDP.
  host :=  (NetNameResolver addressFromString: '239.255.255.250').
  udpSocket sendData: message toHost: host port: 1900.
 buffer := String new:4096.
 MX:1 means we expect replies within 1 second, let's be on the safe side and 
 wait 2
 2 seconds wait.
 read := 1.
 [read  0] whileTrue: [
 read := (udpSocket receiveUDPDataInto: buffer) first.
 Transcript show: (buffer copyFrom:1 to:read)]
 
 Cheers,
 Henry




Re: [Pharo-users] New fast path for proxy loading in Voyage

2015-05-08 Thread Henrik Johansen
A few mistakes were revealed when testing using a real application;1) I'd forgotten to hook up the classFor: method to the proxy creation methods, so it was never actually used...2) Since copyFrom: is just a pseudo-forwardBecome:, we need to explicitly replace existing references to the value returned by selectOne: ...I hope the repository cache is the only place it is stored during selectOne:, if there are more, additional fixup post copyFrom: in becomeForwardWithSameShape: is needed.The attached version should fix the above two issues.Cheers,Henry

Voyage-Mongo-Core-HenrikSperreJohansen.56.mcz
Description: Binary data
On 08 May 2015, at 2:09 , Esteban Lorenzano esteba...@gmail.com wrote:cool, thanks!copied and merged :PEstebanOn 08 May 2015, at 14:00, Henrik Johansen henrik.s.johan...@veloxit.no wrote:Hi Esteban!As we talked about on IRC yesterday, I had hoped to employ the fast become discussed inhttp://forum.world.st/Igor-s-fast-become-for-CompiledMethods-in-Cog-td4345568.htmlto bring faster proxy loading untill Spur arrives.Sadly, it's not present in any current VM's, for reasons unknown*.Luckily, the alternative proposed by Levente in the original thread (http://forum.world.st/A-trick-to-speedup-become-but-not-becomeForward-tp3707064p3708128.html) is appropriate for our case.As I don't have write-access to Voyage repo, I've attached the package with the changes (which work in both 3.0 and 4.0, but I assume not older, due to using the SlotBuilder for anon subclasses)The package comment contains a workspace doit for comparision, but long story short, for objects covered by the new fast path, you can now materialize more thanmillion objects in the time it previously took to materialize five.

Re: [Pharo-users] New fast path for proxy loading in Voyage

2015-05-08 Thread Henrik Johansen

 On 08 May 2015, at 2:12 , Mariano Martinez Peck marianop...@gmail.com wrote:
 
 
 
 On Fri, May 8, 2015 at 9:00 AM, Henrik Johansen henrik.s.johan...@veloxit.no 
 mailto:henrik.s.johan...@veloxit.no wrote:
 Hi Esteban!
 As we talked about on IRC yesterday, I had hoped to employ the fast become 
 discussed in 
 http://forum.world.st/Igor-s-fast-become-for-CompiledMethods-in-Cog-td4345568.html
  
 http://forum.world.st/Igor-s-fast-become-for-CompiledMethods-in-Cog-td4345568.html
 to bring faster proxy loading untill Spur arrives.
 Sadly, it's not present in any current VM's, for reasons unknown*.
 
 Luckily, the alternative proposed by Levente in the original thread 
 (http://forum.world.st/A-trick-to-speedup-become-but-not-becomeForward-tp3707064p3708128.html
  
 http://forum.world.st/A-trick-to-speedup-become-but-not-becomeForward-tp3707064p3708128.html)
  is appropriate for our case.
 As I don't have write-access to Voyage repo, I've attached the package with 
 the changes (which work in both 3.0 and 4.0, but I assume not older, due to 
 using the SlotBuilder for anon subclasses)
 
 
 hahahahah excellent. It was similar to the same idea I have for my proxies in 
 Marea. In my case, what I did is to have 3 types of Proxies (each with each 
 different object format - normal, compact, long), and each of those proxy 
 classes was a variableSubclass. So then when I received the object to 
 proxify, I would create an instance (the correct one from one of those 3 
 proxy classes) of the size of the object to proxify. Therefore, both, the 
 proxy and the target would have same size and format, and therefore I could 
 simply apply Igor idea.

Yeah, it's a really nice fast-path, when the VM's become implementation usually 
involves a heap scan...

In the case of Voyage, we're restricted in that we don't start out with a 
database ID, and not the actual original object, so perfectly pre-shaping the 
proxy is impossible.
Variably sized objects are right out, so I settled on the compromise that was 
easy to do; fixed size objects with equal or greater number of instvars as the 
proxy class.

To do fast swapping with objects of less than 3 slots, the current data held in 
proxy slots would have to be held somewhere external, which is doable, but ugly.
(You can also work around this easily if the performance hit is noticeable by 
adding dummy slots...)
Compact proxies is a really limited use case, since you never store any of the 
builtin ones in buckets directly, you'd have to manually make your mapped 
classes compact.

Seeing as how it's really just a holdover performance hack till Spur is ready 
for use and become: becomes fast, I don't think it makes sense implementing 
either in the context of Voyage. 

Cheers,
Henry

[Pharo-users] New fast path for proxy loading in Voyage

2015-05-08 Thread Henrik Johansen
Hi Esteban!As we talked about on IRC yesterday, I had hoped to employ the fast become discussed inhttp://forum.world.st/Igor-s-fast-become-for-CompiledMethods-in-Cog-td4345568.htmlto bring faster proxy loading untill Spur arrives.Sadly, it's not present in any current VM's, for reasons unknown*.Luckily, the alternative proposed by Levente in the original thread (http://forum.world.st/A-trick-to-speedup-become-but-not-becomeForward-tp3707064p3708128.html) is appropriate for our case.As I don't have write-access to Voyage repo, I've attached the package with the changes (which work in both 3.0 and 4.0, but I assume not older, due to using the SlotBuilder for anon subclasses)The package comment contains a workspace doit for comparision, but long story short, for objects covered by the new fast path, you can now materialize more thanmillion objects in the time it previously took to materialize five.Cheers,Henry

Voyage-Mongo-Core-HenrikSperreJohansen.55.mcz
Description: Binary data
*Need to check we aren't becoming primitive literals before being ok to include? Seriously?You can do ((StandardFileStream  #primRead:into:startingAt:count:) literalAt: 1) at: 4 put: 34 to achieve the same that become apparently must at all costs guard against, does that mean we should also introduce the same kind of primitive fail check requirements to at:put:?I get that there are some objects you really don't want to become: due to VM linking them internally in various ways, but checks that apply to *certain instances* of a class, should be unneccessary, imho (or, better, done at the user site)

Re: [Pharo-users] mac address on windows

2015-05-06 Thread Henrik Johansen

 On 06 May 2015, at 12:29 , Nicolai Hess nicolaih...@web.de wrote:
 
 
 
 2015-05-06 12:10 GMT+02:00 p...@highoctane.be mailto:p...@highoctane.be 
 p...@highoctane.be mailto:p...@highoctane.be:
 I've loaded your package.
 
 A prerequisite is to load OS-Window to make it work.
 
 I've got the DLL call working nicely and the nativeboost with the structure 
 freezing.
 
 This is because you have a recursive datastructure description, but acutually 
 the IP_ADAPTER_INFO structure is not recursive:
 
 PIP_ADAPTER_INFO class fieldsDex 
 ^ #(
  PIP_ADAPTER_INFO  nextVariable;
   DWORD   ComboIndex;
   CHARAdapterName;
   CHARDescription;
 )
 
 The nextVariable should be a pointer to the structure.
 
 from MSDN:
 
  struct _IP_ADAPTER_INFO {
   struct _IP_ADAPTER_INFO  *Next;   - pointer
   DWORD   ComboIndex;
   charAdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
   charDescription[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
   UINTAddressLength;
 
 
 

Also, the pOutBufLen parameter to GetAdaptorInfo is supposed to be a pointer to 
an unsigned long, holding the size of the buffer.
Setting that to an int in the NB declaration, will cause all sorts of trouble...

Cheers,
Henry

Re: [Pharo-users] [Pharo-dev] QualityAssistant v0.4

2015-04-24 Thread Henrik Johansen

 On 24 Apr 2015, at 8:41 , stepharo steph...@free.fr wrote:
 
 I understand the point of marcus but still it is unclear why certain tools 
 should be in and not others.
 Now I would prefer that we have a process that
 
1 := take a miniimage AND load the tools
check that we can unload them (just to check)
and only then declare
 
pharo := 1.
 
Now we will face the problem of ok we do a change and it touches such 
 loaded tools (see the other thread)
Read the Pharo vision paper.
 
 Stef

The problem with Pharo-Dev in olden days wasn't that no one used the image, but 
that there was no good process for pushing required updates to external 
packages, so it was more convenient to just develop in the Core image, and 
leave the other packages for their maintainers to update at the end of a cycle.
I don't think the best answer is to pull more and more packages into the Pharo 
Core repository and effectively do double versioning, as seems to be the 
trend lately...

Why not require write access to repositories of external projects that are 
included in a Pharo-Dev image?
Then you can have the Pharo team responsible for a (currently) #Pharo5 symbolic 
version in the Configuration.
Then, when merging slices, push updates to external repos as appropriate 
(updating #Pharo5 version in Conf), and build new Dev image from a list of such 
approved Configurations.

Lets the external developer do improvements against a static version, and merge 
with latest non-release when appropriate without leaving the comfort of a 
single repository.

Cheers,
Henry




Re: [Pharo-users] Polygons + Skybox in woden?

2015-04-16 Thread Henrik Johansen

 On 16 Apr 2015, at 9:41 , Lusa Nicolas nicolas.l...@usi.ch wrote:
 
 Hello,
 
 I am Nicolas Lusa from university of Lugano and I am working on my master 
 thesis with the supervision of Yuriy Tymchuk.
 Right now I am working with woden and I am trying to build polygons. 
 Question1: Is it possible somehow to build polygons in woden?
 
 If not:
 I know woden is based on OpenGL and I also know that in OpenGL is possible to 
 draw polygons with GL_POLYGON and a given array of points. 
 Question2: How could I use GL_POLYGON through woden for my purpose?
 
 Moreover, I would like to put some sort of skybox in my scene. Apparently 
 it's not possible yet, so my question is how could I do that?
 
 Thanks in advance.
 Cheers.
 Nicolas 

IIRC, Woden is built on modern GL techniques, and GL_POLYGON is deprecated in 
3.0, so I doubt it.
Luckily, triangulation of polygons is pretty much a solved problem, though I 
don't know of any implementations in Pharo yet.



Cheers,
Henry 


Re: [Pharo-users] String operations

2015-04-09 Thread Henrik Johansen
+1.
In addition, half the methods you usually look for is actually implemented in 
their proper place (that is, SequenceableCollection, not String).

Cheers,
Henry

 On 09 Apr 2015, at 12:59 , Sean P. DeNigris s...@clipperadams.com wrote:
 
 Damien Pollet-2 wrote
 Indeed, there is much to say about the String API :)
 Thanks for mentioning this, I'm gathering missing behavior like this !
 
 It seems unanimous that we should add these. I agree that they are useful in
 some cases. However, strings are so general that IMHO there are infinite
 such operations that we could add. Already String methodDict size = 333,
 and one can't depend on method protocols to sort things out because they are
 hijacked for package extensions, so it's easy to be fooled by thinking let
 me check the converting protocol for that and (maybe) finding out later
 that you missed it because #asXyz is in *OtherPackage, which now forces you
 to manually scroll through 333 methods to make sure your desired message
 hasn't been implemented.
 
 So I'm not saying don't add them. I just want to have a conversation
 about:
 1. How often would these be needed? (We should have that conversation about
 most of String's methods)
 2. Do we have any plans for real protocols, with the concepts of privacy and
 package extension extracted into other objects where they belong?
 3. In the mean time, what is a reasonable cognitive limit for an API? For me
 333 is way beyond comprehension with the current tooling, crippled somewhat
 by #2.
 
 
 
 -
 Cheers,
 Sean
 --
 View this message in context: 
 http://forum.world.st/String-operations-tp4817803p4818540.html
 Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
 




Re: [Pharo-users] Native language support

2015-03-12 Thread Henrik Johansen

 On 12 Mar 2015, at 10:39 , Thierry Goubier thierry.goub...@gmail.com wrote:
 
 Hi Nick, Ben,
 
 2015-03-12 10:17 GMT+01:00 Ben Coman b...@openinworld.com 
 mailto:b...@openinworld.com:
 Hi Nick,
 
 The best way to ensure this will get included is log an issue and submit a 
 code slice at pharo.fogbugz.com http://pharo.fogbugz.com/.  Then your code 
 can undergo review and be integrated in a managed way.
 
 I've created an issue:
 
 https://pharo.fogbugz.com/default.asp?15121 
 https://pharo.fogbugz.com/default.asp?15121
There was already a case (with some issues noted to the fix), I linked to that.
Which makes me think, with the duality of communication happening in mailing 
list/issue tracker, it'd be *really* nice if it were possible to have a field 
in the issue tracker where you can link to a mailing list thread, and have the 
tracker post to the thread that an issue has been created...

Cheers,
Henry

Re: [Pharo-users] Notification on GC of an object?

2015-01-16 Thread Henrik Johansen

 On 16 Jan 2015, at 1:25 , Johan Fabry jfa...@dcc.uchile.cl wrote:
 
 
 As I’ve been asked, I’ll clarify a bit more. When I said it worked before I 
 was actually wrong because I had forgotten to remove some alternative cleanup 
 code (the alternative works but it’s like using a cannon to kill a fly).
 
 This is part of the interpreter for Live Robot Programming that Miguel and I 
 are working on. As part of that we need a data structure that holds scopes, 
 for variables but also for other things. It turns out that for the variables 
 part we can map rather nicely to classes, which gives us a bunch of 
 advantages. So for each scope I generate a class. The scope keeps that class 
 in a ‘vars’ instance variable (there are never any instances of these classes 
 BTW). When the scope is garbage collected I want to remove the class from the 
 system. So I put #finalize in the scope with the idea to remove the class, 
 but it turns out that ‘vars’ is always nil. So in the end it did not work out 
 ...

You're probably registering the scope for finalization before setting the vars 
insvar?
The shadow copy is made at the point of registration, so any subsequent 
assignments to the scope's instvars is not accounted for.

Cheers,
Henry


Re: [Pharo-users] Notification on GC of an object?

2015-01-15 Thread Henrik Johansen

 On 14 Jan 2015, at 11:29 , Ben Coman b...@openinworld.com wrote:
 
 what if the object stores a reference to itself? then you can access it from 
 the shadow copy?

GC notification is triggered *after* objects are removed, so even if that were 
to work*, it'd be nil at the time the executor got around to being notified.
For about to be instead of was just GC'd, you'd need Ephemerons, not 
finalization.

Removing a class you're an instance of might be a bit fishy as well. (as I 
understand were to be the case if you only implement #finalize), though it'd be 
nice with some details why it didn't work out for Johan.

Working around that would be specifying a custom #executor instead of 
#finalize, returning an instance of a separate class, with a slot for the class 
to be removed when triggered.
(That executor class would have to implement finalize, of course)

Cheers,
Henry

* The ref would have to be held through a weak array, otherwise the executor 
would have a strong reference to the object, and it'd never be garbage 
collected in the first place... 
Image Roots - WeakReg - Executor - MyObj




Re: [Pharo-users] [ Article ] LampSort, a non-recursive QuickSort implementation

2014-12-09 Thread Henrik Johansen

 On 08 Dec 2014, at 7:36 , Sven Van Caekenberghe s...@stfx.eu wrote:
 
 Hi,
 
 Here is another article I just published
 
  LampSort, a non-recursive QuickSort implementation
 
  The divide and conquer partitioning is at the heart of QuickSort
 
  
 https://medium.com/@svenvc/lampsort-a-non-recursive-quicksort-implementation-4d4891b217bd
 
 Pharo makes it easy to implement this non-recursive version of QuickSort - 
 and beautiful as well.
 
 Sven
 
 
Nice!
A minor nitpick:
partition: interval
  | pivot index |
  pivot := data at: interval first.
  data swap: interval first with: interval last.
  index := interval first.
Doesn't it make more sense to pick the last element as pivot if you're going to 
iterate from the start anyways?
Saves you a swap per partition :)

Cheers,
Henry

Re: [Pharo-users] question on syntax negate numbers

2014-11-10 Thread Henrik Johansen
In VisualWorks:
3 @ Argument expected -- 5

I guess what one expects is a matter of habit, personally I'd expect x - - y to 
yield a parsing error.

Cheers,
Henry

 On 10 Nov 2014, at 12:06 , PBKResearch pe...@pbkresearch.co.uk wrote:
 
 I have tried this on my latest Dolphin (Pro 6.1 Beta 2):
 3 @ -5 is accepted and interpreted correctly.
 3 @ - 5 is rejected with message: ‘Error – incorrect expression start’; the 
 caret is pointing at the – sign.
 So the Opal behaviour does not mirror that of Dolphin.
  
 Hope this helps
  
 Peter Kenny
  
 From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org 
 mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of Thierry Goubier
 
  
 2014-11-10 8:47 GMT+01:00 Henrik Johansen henrik.s.johan...@veloxit.no 
 mailto:henrik.s.johan...@veloxit.no:
 3 @ -5 is not a problem, and accepted by both.
 3 @ - space 5 is what I object to (and Opal allows)
  
 RBParser allows this one even if old Compiler dissallows it (i.e. in Pharo 2).
 
 I haven't tracked if Opal follows the RBParser on that or if this is the 
 reverse (Opal pushed changes on RBParser). I suspect all things RB in Pharo 
 (and Squeak?) are a port from the Dolphin version of RB, which means this is 
 allowed in quite a few other smalltalks (Dolphin?, VW?).
 
 I haven't checked if the SmaCC Smalltalk parser accept that.
 
 Note: 4 - 5 in RBParser does what you would expect. 4 - - 5 as well.
  
 3 @-5 and/or 3 @- 5 is (rightly) disallowed by both.
  
 That one is easier and expected.
 
 My position would be twofold:
 - RBParser is, IMHO, a good parser and I would follow its interpretation. 
 That Opal reuses it is a good point for me.
 - As a programming language designer (and parser implementor), accepting - 5 
 is user friendly, but a bit too contextual in the lexer to be nice to 
 implement.
  
 Thierry
  
  
 Cheers,
 Henry



Re: [Pharo-users] question on syntax negate numbers

2014-11-09 Thread Henrik Johansen

 On 08 Nov 2014, at 5:55 , Werner Kassens wkass...@libello.com wrote:
 
 but if you omit the space between - and 3 the old compiler understands it 
 too, hence its just a convenience thing that cant lead to misunderstandings, 
 or?
 btw opal also understands this:
 -3@2. -- (-3@2)
 i mean, its obvious nevertheless that - is not a method like negated, but 
 part of a number and opal is just a bit more flexible with number formatting.
 werner
 
 On 11/08/2014 04:40 PM, Nicolai Hess wrote:
 Old compiler refuses to accept this code:
 
 - 4 @ -5
 ^-- nothing more expected
 
 Opal compiler does just fine:
 
 - 4 @ -5 - (-4@ -5)
 
 who is right?
 

IMHO, the old compiler is right, whitespace should not be allowed in literals.
For instance, 3 @ - 5 reads like gibberish.

Cheers,
Henry


Re: [Pharo-users] question on syntax negate numbers

2014-11-09 Thread Henrik Johansen

 On 10 Nov 2014, at 8:45 , Thierry Goubier thierry.goub...@gmail.com wrote:
 
 
 
 2014-11-10 7:59 GMT+01:00 Henrik Johansen henrik.s.johan...@veloxit.no 
 mailto:henrik.s.johan...@veloxit.no:
 
 IMHO, the old compiler is right, whitespace should not be allowed in literals.
 
 Whitespace can be \t or \n,\r which makes for strange literals (multilines) 
 such as:
 
 -
 
 5
 
 And would create ambiguity in some cases
 
 is 4 - 5 two literals, or is it two literals separated by the - operator ?
 
 For instance, 3 @ - 5 reads like gibberish.
 
 But is 3 @ -5 a problem or not ? Why is the old compiler accepting -3 @ 5, 
 and not 3 @ -5 ?

3 @ -5 is not a problem, and accepted by both.
3 @ - space 5 is what I object to (and Opal allows)
3 @-5 and/or 3 @- 5 is (rightly) disallowed by both.

Cheers,
Henry

Re: [Pharo-users] Self-removing announcement subscription?

2014-10-27 Thread Henrik Johansen

 On 25 Oct 2014, at 2:42 , Jan B. blizn...@fit.cvut.cz wrote:
 
 Hi all
 
 Today I come with a question regarding announcements.
 I would like to make announcement subscription which would remove itself
 after first use.
 Something like...
 
 anObject announcer 
subscribe: TRMouseDragEnd 
do: [ :event | 
self thisMethodWith: differentParameters. 
anObject announcer removeSubscription: ...this one... ].
 
 All I was able to do is write there
 anObject announcer unsubscribe: self.
 which somehow works, but this instance could have multiple subscriptions and
 it would remove even those I don't want to remove, I need to remove only
 this specific one...
 
 Jan
 
 
 
 --
 View this message in context: 
 http://forum.world.st/Self-removing-announcement-subscription-tp4786622.html
 Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
 

Modify:
AnnouncementSubscription  #deliver: 
 deliver an announcement to receiver. In case of failure, it will be 
handled in separate process

^ (self handlesAnnouncement: anAnnouncement ) ifTrue: [
[action cull: anAnnouncement cull: announcer cull: self] 
on: UnhandledError fork: [:ex | ex pass ]]

and you could use the block:
[:event :announcer :sub |
self thisMethodWith: differentParameters
announcer removeSubscription: sub ]

VW already does this for their announcement implementation, it might be a good 
idea to introduce the third parameter in stock Pharo as well.

Cheers,
Henry

Re: [Pharo-users] UDP example

2014-10-21 Thread Henrik Johansen

 On 21 Oct 2014, at 3:52 , Luc Fabresse luc.fabre...@gmail.com wrote:
 
 
 
 2014-10-21 15:40 GMT+02:00 Sven Van Caekenberghe s...@stfx.eu 
 mailto:s...@stfx.eu:
 
  On 21 Oct 2014, at 15:29, Luc Fabresse luc.fabre...@gmail.com 
  mailto:luc.fabre...@gmail.com wrote:
 
 
  yes examples are good.
  but I also suggest to use a stream on a UDPSocket instead of manipulating 
  the socket directly in the model code.
  Usually, it lowers the code complexity.
 
 Hmm, are you sure that is even possible with UDP sockets ?
 
 I was thinking of using a stream on the data part of the datagram packets.
 If you have structured data it simpler to use #next or #nextImage, ...
 
 And if the data part is bigger than one datagram packet (65535 IIRC), you can 
 append to the stream as soon as you receive the next packet.
 
 Does it sounds good?
 
 Cheers,
 
 Luc

UDP delivery isn't ordered, nor reliable.
Build those into a Stream wrapper in order to reliably reconstruct a data 
stream from the sender, and you're almost back to TCP...

Cheers,
Henry

Re: [Pharo-users] Ridiculous we are

2014-09-26 Thread Henrik Johansen

On 25 Sep 2014, at 8:55 , Alain Rastoul alf.mmm@gmail.com wrote:

 Le 25/09/2014 07:23, Sven Van Caekenberghe a écrit :
 
 On 25 Sep 2014, at 01:04, Alain Rastoul alf.mmm@gmail.com wrote:
 
 Le 25/09/2014 00:06, Sven Van Caekenberghe a écrit :
 Alain,
 
 The character encoding situation in Pharo is pretty good actually. The 
 only problem is that there is some old school code left that encodes 
 strings into strings, but today you can easily write much better and 
 conceptually correct code.
 
 You could have a look at this draft chapter of the upcoming 'Enterprise 
 Pharo' book that I am currently writing:
 
   http://stfx.eu/EnterprisePharo/Zinc-Encoding-Meta/
 
 Concerning file system paths, FilePathEncoder and FilePluginPrimitives 
 already do the right thing.
 
 Now, your idea about using UTF-8 to represent internal Strings is 
 something that has been discussed before and in many other languages as 
 well. The short answer is that due to it being variable length, the 
 inefficiency is (probably) just too high. Simple indexed access becomes a 
 problem, let alone more complex string manipulations. I am not saying that 
 it cannot be done, I think it is just not worth the trouble. The current 
 solution in Pharo with ByteString and WideString is quite nice (check the 
 chapter I mentioned before).
 
 Sven
 
 Very interesting !
 It seems that most of what I was saying is already here :)
 I was not saying that Pharo should use utf8 (I mentionned utf8 because it 
 is a standard, but I find the variable length encoding very weird), I was 
 rather talking of using WideString in UTF 16 or 32 and that's done.
 I saw asWideString but didn't know about automatic convertion or codepoint 
 selector and internal wide string support.
 Does it means that Pharo Greek users (for example) use WideString for 
 Strings without having to specify it or make explicit convertions (except 
 of course when dealing with bytes if they want to) ?
 If yes, very good, job is almost done :)
 (personnally I would also deprecate ByteString, and get rid of it, just my 
 opinion).
 Thanks for the link, another good chapter .
 
 Regards,
 
 Alain
 
 ByteString is important because it is an optimalization of the most common 
 case.
 
 I understand the point here, memory/data footprint, cpu cache and so on (not 
 talking of encoding/decoding).
 I think that's why Microsoft choosed UTF16 (old UCS2) as a middle solution 
 because it covers most of character sets with 2 bytes.

It used to be a middle solution, back when UCS2 could encode the entire defined 
Unicode set.
Novadays it's just the worst of both worlds; you waste memory for most normal 
text, *and* you don't have constant time indexed code point access.

The duality we have in Pharo is an attempt to achieve the *best* of both 
worlds, wasting little memory for the normal case (latin1), and maintain 
constant time indexed access in all cases.
The ultimate solution for this approach would have a trio of string classes 
with slot sizes 8 - 16 - 32 expanding / contracting as needed, but we don't 
have classes with variable short slots. (currently, they're planned in new Cog, 
if I've understood Eliots new object format correctly)

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Passed by references and by value

2014-09-26 Thread Henrik Johansen

On 26 Sep 2014, at 8:24 , Marcus Denker marcus.den...@inria.fr wrote:

 
 On 25 Sep 2014, at 20:28, Esteban A. Maringolo emaring...@gmail.com wrote:
 
 2014-09-25 15:14 GMT-03:00 nacho 0800na...@gmail.com:
 Hi,
 In PBE says that ordinary objects' ivars are passed by references and small
 integers are passed by value.
 Is there a way to know if a class is passed by reference or by value?
 
 Only small integers are passed as value?
 
 Yes.
 
 It has to do with the object headers, SmallIntegers are embedded in the OH.
 
 
 In the *reference*, not the header. The reference points to a header for a 
 normal
 object, for small-integers the reference *is* the integer value. This means 
 that
 there is no header for the integers.
 
   Marcus

So, a succinct phrasing indifferent to object format, using a relatively 
well-defined term, would be: 
Only immediate objects are passed by value.

(Which means you have to explain immediate objects, as markus did)

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Ridiculous we are

2014-09-25 Thread Henrik Johansen

On 25 Sep 2014, at 5:00 , Hilaire Fernandes hila...@drgeo.eu wrote:

 Le 24/09/2014 18:48, Benjamin Pollack a écrit :
 On Tue, 23 Sep 2014 08:51:54 -0400, Hilaire hila...@drgeo.eu wrote:
 
 Le 23/09/2014 14:09, Damien Cassou a écrit :
 I recently read documents about utf-8 encoding. In all of them, the
 author says that pathnames should be kept as is because you never know
 which encoding the filesystem uses. So, a filename should probably be
 a bytearray.
 
 
 yes, but a #é should be encoded in two bytes.
 
 As noted in my previous message, é could be represented as either
 one or two Unicode code points, and these in turn could validly be
 either two or three bytes in UTF-8.  My gut says that $é should be
 U+00E9, because otherwise you should have to use two Characters ($e
 and $´), but you could legitimately argue otherwise as well, and at
 any rate, #é could definitely be either.  This is likely the core of
 the issue you're hitting.
 As I understand it, #é should be encoded on two bytes and only two byte.
 Only ASCII is coded as 1 byte with UTF-8.
 See ref. on Wikipedia

Hilaire: Benjamin is talking about which unicode normalization form é should be 
represented in, which is orthogonal to the encoding; 
http://en.wikipedia.org/wiki/Unicode_equivalence#Combining_and_precomposed_characters
 .
So é can indeed be encoded in two different ways in utf8 (as in any other 
encoding), both as #[c3 a9] (encoding U+E9, Latin small letter e with acute), 
and as #[65 cc 81] (encoding U+65, Latin small letter e, followed by U+0301, 
Combining accute accent)

Benjamin: Since the base path that contains the problematic character 
originates from a filesystem primitive, we can safely assume it's already in a 
canonical form*, Pharo does no automatic normalization. (that is, if the path 
would have been e + ´, the internal string would have two separate characters 
as well)

Cheers,
Henry

* Only Mac OSX defines a canonical form for its paths anyways, the others don't 
care


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Ridiculous we are

2014-09-25 Thread Henrik Johansen

On 22 Sep 2014, at 10:07 , Hilaire hila...@drgeo.eu wrote:

 
 However font path seems ok:
 File @ /home/hilaire/Téléchargements/DrGeo.app/Contents/Resources.
 Inspecting this path, it looks like 'Téléchargements' is 8 bits, but it
 should be utf-8, right?
 
 I think there are issue on Windows, as some user reported to me.


The fun thing about plugins calling external libraries, is that you have to 
find out what that library does to know the right answer to what encoding char* 
parameters are meant to be passed...

In the case of FreeType, after some digging*, it seems to me it ends up calling 
fopen on all platforms, which on windows... *drumroll*
... resolves to the legacy ANSI version** of the Windows file libraries. 
Hence, the correct encoding to use on Windows would be the locale legacy code 
page.
It also means that, on Windows, you *cannot* load fonts from a directory whose 
name is not encodable in the current codepage no matter what we do in Pharo. 
(short of submitting a bug-fix to the FreeType project)

Cheers,
Henry

*FT_New_Face 
(http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/src/base/ftobjs.c)
 calls...
FT_Open_Face  (same) which calls...
FT_Stream_New  (same) which calls...
FT_Stream_Open 
(http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/src/base/ftsystem.c)
 which calls...
ft_fopen 
(http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/include/config/ftstdlib.h)
 which resolves to
f_open.

** http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx , don't be fooled, the 
Unicode support section is about contents written/read to/from file, not the 
path parameter.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] LF instead of CR for new lines or writing about Pharo inside Pharo

2014-09-23 Thread Henrik Johansen

On 23 Sep 2014, at 6:28 , Offray Vladimir Luna Cárdenas off...@riseup.net 
wrote:

 Hi :-),
 
 A small answer to myself that can be useful is someone find this thread:
 
 I have seen some post on Internet about CR and LF issues on Pharo Smalltalk, 
 like this:
 
 [1] 
 http://stackoverflow.com/questions/11739548/how-to-correctly-decode-text-files-from-filesystemreadstream-in-pharo-1-4
 [2] http://stackoverflow.com/questions/1598054/smalltalk-newline-character
 
 A detailed search on the web take me to this:
 
 http://magaloma.seasidehosting.st/Collections-Strings
 
 Here I searched for replace and found the proper method:
 
 
 withInternetLineEndings
 change line endings from CR's to CRLF's. This is probably in
 prepration for sending a string over the Internet
 
 
 So taking my string and sending:
 
  myString contents withInternetLineEndings
 
 did the trick.
 
 I hope it will be helpful for future newbies.
 
 Cheers,
 
 Offray

A better solution if you are writing to file, and still want to keep the string 
in image with its default line ending, is using the lineEnding conversion of 
the Stream (MultiByteFileStream  lineEndConvention:).

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Ubuntu Font License : Compatibility with Pharo License?

2014-09-22 Thread Henrik Johansen

On 19 Sep 2014, at 9:46 , Mayuresh Kathe mayur...@kathe.in wrote:

 Would the Ubuntu Font License at; http://font.ubuntu.com/licence/ be 
 considered compatible with the Pharo license?
 
 If it is not _compatible_ would the usage of Ubuntu fonts still be 
 acceptable/permissible within Pharo?
 
 Thanks,
 
 ~Mayuresh


Pharo is MIT, you can do what you want with it.
If you mean compatible in the sense that you may 

a) Make a loadable package which honours the UFL, which can be loaded and used 
in a Pharo image
b) Put the Freetype font files alongside your image (along with licensing 
notice), and set it as your default font

then yes, it is compatible.

What I don't think could be done, is embed them in a distributed Pharo release, 
since UFL specifically prohibits relicensing, and it's a goal to keep the 
distribution itself as MIT, not MIT with certain parts under the UFL. Nothing 
stops you from doing that in an image you intend to distribute yourself though, 
because hey, MIT.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Math Ontologie on Pharo 3.0

2014-09-10 Thread Henrik Johansen
IIRC, there are two sources of imported code in Monticello.
By default it reads from the DataStream encoded .bin file, which stores source 
containing wide character as... a binary WideString.
Unless the .bin file is somehow corrupted, importing non-ascii .mcz therefore 
works as long as you have a working DataStream reader. * 
If that path fails, it will read from the .st file, which, IIRC, had utf8 
encoding added quite recently by Nicolas Cellier. 


So to narrow this down further, one has to ask:
For what reason did the DataStream reading fail?
- Did the DataStream get written (correctly)?
- Did the DataStream fail to read a correctly written file? (f.ex. due to class 
shape changes in image, without proper backwards compat reading methods added)
Why didn't the fallback .st work?
- Did the .st file write out as utf8? (could be the case not if written from an 
older image, but then I'd expect the FileStream to barf, not the compiler)
- Did the .st get written as the *correct* utf8?
- Did the .st file read in as utf8? 

Once which combination of those things failed in this case is found, it should 
be easier to see what a fix could/should be.

Cheers,
Henry

* Which is why non-ascii packages at least used to fail to import in Gemstone, 
their DataStream reader could not translate WideString instances to the proper 
internal string representations, and the fallback .st didn't use to be properly 
encoded. IIRC, the VW reader goes straight for the .st, so same problem there. 
There's a reason Seaside has ascii-only as a requirement :)

On 09 Sep 2014, at 7:07 , Sven Van Caekenberghe s...@stfx.eu wrote:

 Check/read my mail again: I don't think it is the compiler (my tests show it 
 is not), then it must be Monticello, in the sense that it treats its input 
 stream (encoding) wrongly.
 
 On 09 Sep 2014, at 15:25, Clément Bera bera.clem...@gmail.com wrote:
 
 
 
 2014-09-09 14:12 GMT+02:00 Alain Busser alain.bus...@gmail.com:
 Is this a reproducible case? 
 http://ss3.gemstone.com/ss/MathsOntologie/MathsOntologie-AlainBusser.68.mcz
 
 
 Well I tried to merge that in the latest Pharo 4.
 
 With Opal I got the error 'unknown character'
 
 With the old compiler I got unmatched string quote.
 
 If it's French, could it be a ' ? 
 
 It looks like a parser bug to me...
 
 
 I hope not :-)
 
 Alain
 
 On Tue, Sep 9, 2014 at 5:43 AM, Clément Bera bera.clem...@gmail.com wrote:
 What kind of bug do you have with accent ? Do you have a stack trace ?
 
 More importantly, can you give us a reproducible case ? I will investigate 
 tomorrow if you have a reproducible case to check if this is due to Opal.
 
 It may also be recent changes related to fonts.
 
 2014-09-08 21:07 GMT+02:00 Sven Van Caekenberghe s...@stfx.eu:
 I don't think it is related to Opal: I made a test class with an instance 
 variable, accessor and class comment with accents - which I can file out and 
 file in:
 
 
 
 
 
 
 
 I tested in 3.0 and 4.0
 
 The problem might be with Monticello.
 
 
 On 08 Sep 2014, at 20:05, Hilaire hila...@drgeo.eu wrote:
 
 Oh, by the way, it looks like the accents are on the instance variable 
 names.
 
 I edited the subject to not pollute the original discussion thread.
 
 Hilaire
 
 Le 08/09/2014 20:01, Hilaire a écrit :
 Marcus,
 
 Alain's MathOntologie package provide Classes and Messages with French
 accent, to ease the understanding of programming to high school students.
 I am suspecting the new compiler or something related does not accepted
 accented caracters or something different to ASCII.
 
 Alain, in your package I noted the sources is not utf-8 but iso-8859-15
 (8 bits), I converted it to utf-8 and tried to get it loaded in Pharo3,
 but still accent characters caused problem, see screenshot.
 
 Enclosed source file utf-8 converted and improper imported source code
 with accented variable name.
 
 Hilaire
 
 Le 08/09/2014 12:18, Alain Busser a écrit :
 Hi,
 
 I don't know if it is related but I have problems importing french files
 inside Pharo 3: Anytime when there is an accentuated character there is
 an error, and the file is not imported. Even if the character is a quote
 inside double quotes (like in it don't work) there is an error
 message. Right now I can't import MathsOntologie
 (http://ss3.gemstone.com/ss/MathsOntologie/MathsOntologie-AlainBusser.68.mcz)
 
 into Pharo 3 and I have to go on developing it in Pharo 1.4...
 
 Alain
 
 
 
 
 
 --
 Dr. Geo - http://drgeo.eu
 iStoa - http://istao.drgeo.eu
 
 
 
 
 
 
 
 
 



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Seeing all the methods that is used in a method

2014-08-07 Thread Henrik Johansen

On 07 Aug 2014, at 10:41 , kilon alios kilon.al...@gmail.com wrote:

 cant you also use the ast to find out how exactly Pharo which object and 
 which method it executes ? 

No. Consider:

#do: aBlock
aBlock value

Finding the methods actually executed by this is a hard problem.
You’d at least need inferred types (to find the values of block that are 
actually sent to THIS #do: implementation) to even attempt to make a somewhat 
accurate prediction.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Base64 encoding + UTF8 ?

2014-06-12 Thread Henrik Johansen

On 11 Jun 2014, at 10:28 , Sven Van Caekenberghe s...@stfx.eu wrote:

 Bonsoir François,
 
 From the class comment of ZnBase64Encoder:
 
 [...]
 Note that to encode a String as Base64, you first have to encode the 
 characters as bytes using a character encoder.
 [...]
 
 Sending #asByteArray to a String is the same as doing no encoding (or doing 
 null encoding).
 
 Consider:
 
 ZnBase64Encoder new encode: (ZnUTF8Encoder new encodeString: 
 'tamèreenslipdeguerre'). 
 
 = 'dGFtw6hyZWVuc2xpcGRlZ3VlcnJl'
 
 ZnBase64Encoder new encode: (ZnByteEncoder iso88591 encodeString: 
 'tamèreenslipdeguerre'). 
 
 = 'dGFt6HJlZW5zbGlwZGVndWVycmU='
 
 ZnBase64Encoder new encode: (ZnNullEncoder new encodeString: 
 'tamèreenslipdeguerre'). 
 
 = 'dGFt6HJlZW5zbGlwZGVndWVycmU='
 
 The last two are often the same, and thus equivalent to #asByteArray, but not 
 always.
 
 HTH,
 
 Sven

In other words, Base64 isn’t really an encoding, it’s a transfer format, whose 
purpose is to only transmit bytes with safe values that have no chance of 
being interpreted as control sequences by a set of protocols.

Encoding Strings - Bytes is a separate concern.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Xcode's Swift Playground

2014-06-04 Thread Henrik Johansen

On 03 Jun 2014, at 6:32 , Camille Teruel camille.ter...@gmail.com wrote:

 
 On 3 juin 2014, at 17:34, Johan Fabry jfa...@dcc.uchile.cl wrote:
 
 
 On Jun 3, 2014, at 4:21 AM, Camille Teruel camille.ter...@gmail.com wrote:
 
 To what I understand, types are inferred, it is not statically typed. Am I 
 wrong ? 
 
 If there is type inference then it is statically typed (at least partially 
 if not every variable type can be inferred)
 
 To repeat myself: this is not the case. Example is the RoelTyper.
 
 Yes, there are many type inferencers for dynamically-typed languages.
 But that's not because one builds a type inferencer for say Smalltalk that I 
 can say Smalltalk has type inference: the inferencer is not integrated 
 within the language, it's just an analysis tool on top.
 If someone says that his language has type inference, he means that the type 
 inferencer is built into the language, and normally there is some type 
 checking and/or the compiler is designed to leverage type information which 
 means that the language is at least partially statically-typed (if not 
 entirely).
 Because if a language does no type checking nor type-based optimisations, for 
 what purpose would it have type inference built into it?

Inferred types have an often overlooked purpose that, IMHO, in dynamic 
languages, is their biggest benefit. 
That being, it can reduce the number of false positives in common development 
actions such as auto-complete, searching for implementors, etc.

A pharo with built-in type inference would be no better.
A pharo with built-in type inference, and tools utilizing it, would.

It’s a bit of a shame that programmer productivity is a less favourable 
research area than optimization, when in that case, using the much cheaper type 
info from PIC’s instead, yield equivalent results.
(ref. http://www.cs.ucsb.edu/~urs/oocsb/papers/oopsla95-tf.pdf)

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Probabilities package for Pharo?

2014-04-24 Thread Henrik Johansen

On 24 Apr 2014, at 11:25 , Sebastian Tleye stl...@gmail.com wrote:

 Thanks Markus, I didn't try it but I will!
 
 
 2014-04-24 11:20 GMT+02:00 Markus Fritsche mfrits...@reauktion.de:
 On 2014-04-24 11:10, Sebastian Tleye wrote:
 
 Hi,
 
 I am doing some experiments in Pharo and I need to model Normal and 
 Log-Normal distributions in pharo.
 Is there any existing package for that?
 
 Hello Sebastion,
 
 have you tried the NumericalMethods Package in the Configuration browser? 
 It loads a package DHB, which includes the class DhbNormalDistribution.
 
 
 Best regards,
   Markus
 
 
If the package is anything like the one in VisualWorks (In other words, 
LogNormalDistribution a subclass of ProbabilityDensityWithUnknownDistribution), 
you probably want to implement
LogNormalDistribution  distributionValue: aNumber
Answers the probability of observing a random variable 
distributed according to
 the receiver with a value lower than or equal to aNumber.
^aNumber  0 
ifFalse: [0]
ifTrue: [normalDistribution distributionValue: aNumber ln]

rather than rely on the supers implementation, if you plan on using it.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Athens and ellipse drawing

2014-04-23 Thread Henrik Johansen

On 22 Apr 2014, at 2:23 , Igor Stasenko siguc...@gmail.com wrote:

 as for why there's 4 arc segments instead of one, its because 
 of bad approximation, when drawing more that 90 degree arcs.
 
 also, in athens, arc segment is defined with following inputs:
 - end point of previous segment (implicit)
 - angle
 - direction (clockwise/counterclockwise)
 - end point
 
 the radius, therefore calculated automatically, because with given set of 
 parameters there's only one way to draw an arc connecting given points.
 
 Now if you put angle of 360 degrees, you cannot draw arc without specifying 
 radius,
 because your end points will coincide, which means there's infinite number of 
 ways to draw full circle passing through a single point, with any radius. 
 
 cairo using different inputs for specifying arc segments..
 - center, radius, start angle, end angle
 
 the problem with such parametrization is that it is completely separate from 
 rest of commands (line/move/bezier etc).. and you will be very lucky if your 
 arc will be connected with rest of your path.. because arc's starting point 
 depends on start angle, instead of last point of previous path segment.
 
 this was the main reason to use more appropriate parametrization to get rid 
 of inconsistency.. while losing ability to draw full circle with single 
 command..

AFAICT, still doesn’t explain how to draw an ellipse with constant stroke path 
width, which was the original question :)

One way is to not use a transformed circle path altogether, but draw the actual 
ellipsis path using cubic beziers:
http://www.charlespetzold.com/blog/2012/12/Bezier-Circles-and-Bezier-Ellipses.html

ellipsisOfExtent := [:builder :anExtent | | halfX halfY |
halfX := anExtent x / 2.
halfY := anExtent y / 2.
“We expect relative builder, and start the ellipsis at anExtent 
x / 2 @ 0
builder 
curveVia: 0@(halfY negated * 0.55) and: (0.45 * 
halfX)@halfY negated to: halfX@ halfY negated;
curveVia: halfX* 0.55 @ 0 and: halfX@ (0.45 * halfY) 
to: halfX @ halfY;
curveVia: 0 @ (halfY * 0.55 ) and: (0.45 * halfX 
negated @ halfY) to: halfX negated @ halfY;
curveVia: (halfX negated * 0.55) @ 0 and: halfX negated 
@ (halfY negated * 0.45) to: halfX negated @ halfY negated;
close].

AthensSceneView new
scene: [ :can |
| path |

path := can
createPath: [ :builder | 
builder moveTo: 10@60.
ellipsisOfExtent value: builder value: 
200@100 ].
(can

setStrokePaint: Color red) 
width: 8 asFloat.
can drawShape:  path ] ;
openInWindow

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Athens and ellipse drawing

2014-04-23 Thread Henrik Johansen

On 23 Apr 2014, at 2:31 , Igor Stasenko siguc...@gmail.com wrote:

 
 
 
 On 23 April 2014 13:17, Henrik Johansen henrik.s.johan...@veloxit.no wrote:
 
 On 22 Apr 2014, at 2:23 , Igor Stasenko siguc...@gmail.com wrote:
 
  as for why there's 4 arc segments instead of one, its because
  of bad approximation, when drawing more that 90 degree arcs.
 
  also, in athens, arc segment is defined with following inputs:
  - end point of previous segment (implicit)
  - angle
  - direction (clockwise/counterclockwise)
  - end point
 
  the radius, therefore calculated automatically, because with given set of 
  parameters there's only one way to draw an arc connecting given points.
 
  Now if you put angle of 360 degrees, you cannot draw arc without specifying 
  radius,
  because your end points will coincide, which means there's infinite number 
  of ways to draw full circle passing through a single point, with any radius.
 
  cairo using different inputs for specifying arc segments..
  - center, radius, start angle, end angle
 
  the problem with such parametrization is that it is completely separate 
  from rest of commands (line/move/bezier etc).. and you will be very lucky 
  if your arc will be connected with rest of your path.. because arc's 
  starting point depends on start angle, instead of last point of previous 
  path segment.
 
  this was the main reason to use more appropriate parametrization to get rid 
  of inconsistency.. while losing ability to draw full circle with single 
  command..
 
 AFAICT, still doesn’t explain how to draw an ellipse with constant stroke 
 path width, which was the original question :)
 
 
 Right, what is missing is elliptical arc segment type. And there's no direct 
 support for it in Cairo.. so it can be only approximated by other segment 
 types, like lines or bezier curves.
 There's a work started on calculating path geometry using approximation with 
 line segments.. it can be used to represent any kind of curves defined 
 parametrically.
 But it is not yet plugged into the API.
 
 
 One way is to not use a transformed circle path altogether, but draw the 
 actual ellipsis path using cubic beziers:
 http://www.charlespetzold.com/blog/2012/12/Bezier-Circles-and-Bezier-Ellipses.html
 
 ellipsisOfExtent := [:builder :anExtent | | halfX halfY |
 halfX := anExtent x / 2.
 halfY := anExtent y / 2.
 “We expect relative builder, and start the ellipsis at 
 anExtent x / 2 @ 0
 builder
 curveVia: 0@(halfY negated * 0.55) and: (0.45 * 
 halfX)@halfY negated to: halfX@ halfY negated;
 curveVia: halfX* 0.55 @ 0 and: halfX@ (0.45 * halfY) 
 to: halfX @ halfY;
 curveVia: 0 @ (halfY * 0.55 ) and: (0.45 * halfX 
 negated @ halfY) to: halfX negated @ halfY;
 curveVia: (halfX negated * 0.55) @ 0 and: halfX 
 negated @ (halfY negated * 0.45) to: halfX negated @ halfY negated;
 close].
 
 AthensSceneView new
 scene: [ :can |
 | path |
 
 path := can
 createPath: [ :builder |
 builder moveTo: 10@60.
 ellipsisOfExtent value: builder 
 value: 200@100 ].
 (can
 
 setStrokePaint: Color red)
 width: 8 asFloat.
 can drawShape:  path ] ;
 openInWindow
 
  
 quite nice approximation. What is an error measure comparing to true ellipse?

From the abstract of the paper cited in the linked site:

We provide a surprisingly simple cubic Bézier curve which gives a very accurate 
approximation to a segment of a circle. Joining the Bézier segments we obtain 
an approximation to the circle with continuous tangent and curvature. For 45° 
segments the error is approximately 2·10-6, and in general the approximation is 
sixth order accurate.

Considering the code simply stretches a bezier circle’s control points, I’d say 
quite. In fact, I’d be surprised if the arc primitive in cairo is implemented 
using a different method.

(Of course, even less error using the actual value of the formula for 90 
degrees, instead of approximate values .55 / 1- 0.55.)


Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Loop problem on Dr Stef

2014-03-31 Thread Henrik Johansen

On 30 Mar 2014, at 1:45 , Roelof Wobben r.wob...@home.nl wrote:

 Hello,
 
 When I select this part:
 
 1 to: 100 do:
  [:i | Transcript show: i asString; cr ].
 
 And do print it.
 
 I only see 1 where I expected to see all the numbers from 1 till 100.
 
 What went wrong ?
 
 Roelof
 
 

print it prints the return value of the expression.
In the above case, that is the return value of the to:do: method, which is the 
receiver, so 1 is printed.
(If you read the implementation of to:do: on Number, you’ll see there is no 
explicit return using ^ , in such cases the return is always the receiver)

If you wanted to print a list of 1 .. 100 (which would be printed with print 
it), you’d use a method which returns such a collection for example collect:;
(1 to: 100) collect: [:each | each ].

The () are needed, since there is no to:collect: method, so instead we send  
collect: to an interval, which we create using 1 to: 100.

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Drawing a line

2014-01-16 Thread Henrik Johansen

On 16 Jan 2014, at 10:52 , Маркіян Різун mri...@gmail.com wrote:

 Hello!
 
 Task is simple - draw a line on a form(actually this line will be a border of 
 a cell). While browsing classes I found LineSegment and LineMorph. Which of 
 them is better to use in my case? And another question: I know how to 
 initialize both of them, but don't know how to draw it on my form.
 
 Thank you for help.
 Mark 

myForm getCanvas line: pt1 to: pt2 width: w color: c

You only need to use a LineMorph if the line is not supposed to be static, 
otherwise drawing it directly on the Form is just as easy.

Unless what you actually want is to create something like a spreadsheet, in 
which case a CellMorph, with RectangleMorph (cell outline) / StringMorph (cell 
contents) as subcomponents would probably be a better solution.
(And the spreadsheet itself a morph, with CellMorphs as subcomponents) 

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] voyage/mongo randomly wrong OIDs

2013-09-02 Thread Henrik Johansen

On Aug 30, 2013, at 4:35 , Esteban Lorenzano esteba...@gmail.com wrote:

 
 On Aug 29, 2013, at 5:08 PM, Sven Van Caekenberghe s...@stfx.eu wrote:
 
 
 On 29 Aug 2013, at 16:51, Esteban Lorenzano esteba...@gmail.com wrote:
 
 hi
 
 well... I've never been happy on using the UUID generator for my keys, but 
 is the fastest option I found. 
 There are, of course, alternatives: 
 
 1) Using your own number generator (sequential, or whatever). Problem with 
 that is that is image based, then you need a persistence strategy... then 
 you are slow. 
 2) then you can use your own procedure in mongo... with same problem than 
 (1)
 3) you could use timestamp. but TimeStamps are slow :(
 
 anyway... I open to ideas :)
 
 in the mean time, you can check if your UUID generator is using the 
 primitive or not. In you are not, you have more possibilities of having a 
 collision. 
 
 Yes, the Smalltalk code (type 4 UUID) is just a random number that is 
 computed in a complex way.
 
 What does the primitive actually do ? Is it different ?
 
 the primitive uses the clock ticks to produce an UUID... you shouldn't have 
 repeated numbers that way... but well, it depends on the platform 
 implementation also. 

Wait, which primitive is this? UUID  primMakeUUID? 
That code calls libUUID, which (as long as it doesn't crash :P) fetches from 
dev/urandom (or the windows equivalent RtlGenRandom), there shouldn't ever be a 
problem getting duplicate results unless  those system-provided resources are 
bugged, in which case your entire system is borked.

The fallback code using UUIDGenerator default admittedly has a weak PRNG, and 
is dog slow:
gen := UUIDGenerator new.
[gen generateFieldsVersion4] bench '12,900 per second.'
[ UUID new ] bench '3,610,000 per second.' Primitive working, btw

but that  hardly means you should run into duplicate sequential UUID's…

The *only* way sequentially equal UUID's  could arise, is if one uses 
UUIDGenerator directly, and creates a new instance each time, which does indeed 
run the risk of returning values derived from the same Time initialization , 
but that should *never* be done…

Cheers,
Henry




signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] image resize event

2013-08-20 Thread Henrik Johansen

On Aug 19, 2013, at 6:07 , Usman Bhatti usman.bha...@gmail.com wrote:

 Hello,
 
 I would like to resize all my windows opened inside my image when resizing 
 the image window. Can anyone point me to the hook where I can plug my code 
 for window resizing?
 
 For example, it would like to do
 onImageResize
   World fitAll.
 
 tx,
 
 usman

You need to install a #windowEventHandler: on the World, this will receive all 
host window events, such as resizes.
Make sure you also handle #windowClose events if you want the native X button 
to work, as per PasteUpMorph  #windowEvent: 

Cheers,
Henry


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] your opinion about storing FixedDecimal in Mongo

2013-08-19 Thread Henrik Johansen

On Aug 19, 2013, at 10:38 , Sabine Knöfel sabine.knoe...@gmail.com wrote:

 Hi,
 
 I am interested in your opinion.
 I use FixedDecimal for computing currency amounts.
 This works fine.
 
 When storing the amounts with voyage into mongo (I have a lot of them!!!),
 normally, one currency amount would be stored into mongo as follows:
 
   vatAmountEUR: {
 #instanceOf: FixedDecimal,
 negative: false,
 number: NumberInt(90280),
 part1: NumberInt(9),
 part2: NumberInt(280),
 scale: NumberInt(4) 
  } 
 
 I think, this is a lot of stuff for one single value. I tend to convert the
 FixedDecimal into a Float for storing it. In this case, it would be like
 this:
 
 vatAmountEUR: 0.7196 
 
 When loading, I immediately re-convert it into a FixedDecimal. I would do NO
 computing with the float(!!).
 
 What is your opinion about this (rounding issues, performance, database size
 etc.)?
 Do you think, there is something against it? What would you do?
 
 Sabine

There are rounding issues even without doing arithmetic, conversion scaled - 
float WILL inherently be lossy due to float's fixed size.
You are only ensured 15 decimal digits of precision with 64-bit floating point 
numbers like in Pharo (BSON Doubles):
98765432109.87658s5 asFloat asScaledDecimal: 5 98765432109.87659s5

Though, Compared to using NumberInt ( a signed 32-bit integer, with max 9 
digits) for storing the unscaled number, it's actually the better option… 

I guess the morale is, either way, as long as you are storing values in fixed 
size data fields (and not say, a String), you need some checks in place to 
ensure the numbers you are saving are within valid ranges. ;)

Cheers,
Henry



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [Pharo-users] Garbage collector Memory Profiling

2013-07-31 Thread Henrik Johansen

On Jul 31, 2013, at 3:23 , Mariano Martinez Peck marianop...@gmail.com wrote:

 As far as I know, that's not possible in Pharo unless you explicitly register 
 the desired objects in WeakRegistry default or similar (and implement 
 #finalize).
 I think is the closest you have.
 
 Cheers,

A few clarifications:
 - You can use a non-default WeakRegistry (usually one specific to your domain, 
to avoid cluttering of the default one)
- You can specify a custom executor (any object which implements #finalize), 
rather than implement #finalize on objects you're interested in.

obj := Object new.
executor := ObjectFinalizer receiver: Transcript selector: #show: argument: 
'Object GC''d!'.
myReg := WeakRegistry new.
myReg add: obj executor: executor.
obj := nil.
Smalltalk garbageCollect.

Cheers,
Henry