FAQ Database Discussion Community


Why shouldn't I store into literal arrays in Smalltalk?

smalltalk,pharo,squeak
Some style-guides and idioms suggest that you should not mutate literal arrays, like in this case: MyClass>>incrementedNumbers | numbers | numbers := #( 1 2 3 4 5 6 7 8 ). 1 to: numbers size: do: [:index | numbers at: index put: (numbers at: index) + 1]. ^ numbers...

Smalltalk - Is it possible to add a string to a String instance via a method?

smalltalk,pharo
Smalltalk - Is it possible to add a string to a String instance via a method? Essentially I'd like something along the lines of: renderThisOn: aString aString append: 'whatever text I want' Essentially I'd like a String instance (ByteString, etc) to behave like the "html" object in Seaside. I pass...

Pharo Smalltalk - Message forwarding, is it possible to intercept a message and redirect it to another Object (instance)?

smalltalk,pharo
Pharo Smalltalk - Message forwarding, is it possible to intercept a message and redirect it to another Object (instance)? In Objective-C there's forwardInvocation: that gets called right before an exception is thrown so you can do something about the message you received and know nothing about. Is there something similar...

Multiple ifs in Smalltalk

refactoring,conditional-statements,smalltalk,pharo
I'm really new to smalltalk and still trying to figure out the basic stuff. Below is a simple program I wrote. It is supposed to print "a" if the number can be divided by 5, "b" if it can be divided by 3, and "ab" if it can be divided...

Double dispatch in Pharo

smalltalk,pharo,double-dispatch
Could someone please explain the process of double dispatch in Pharo 4.0 with Smalltalk? I am new to Smalltalk and am having difficulty grasping the concept, since it is implemented very differently in Java as compared to Smalltalk. It will be very helpful if some one could explain it with...

Seaside - What's the point of implementing #children in a WAComponent when a direct call to “html render:” is made in “renderContentOn: html”?

smalltalk,pharo,seaside
Whatever >> children ^Array with: oneComponent with: anotherComponent. Later in the code one might have something like this. Whatever >> renderContentOn: html ... html render: oneComponent. ... html render: anotherComponent. Since I make a call explicitly to render these components, what's the use of having them in #children? Is #children...

Seaside in Pharo Smalltalk - How do I enable opening the “classic” debugger (error handler) when an exception occurs?

smalltalk,pharo,seaside
Seaside in Pharo Smalltalk - How do I enable opening the "classic" debugger when an exception occurs? Right now my WAComponents display an exception error in the webpage viewing the Seaside App. Is it possible to raise in exception in the image itself and have the 'classic' debugger pop up?...

Syntax for class and instance variables and methods in Pharo 4.0

smalltalk,pharo
I am learning Pharo online and am not sure if I got the syntax correct for creating class and instance variables. Please correct me if I am wrong :- Class (Static) method created on class side of Pharo, where name, email, phone are instance variables of class CreateUser: createNewUser:Arguments name:userName...

How to identify “Space is low” cause

memory,memory-leaks,pharo
So sometimes you get "Space is low" dialog in Pharo. Is it possible to somehow identify what is taking that much space?

Pharo 4 FFI current state and the future

ffi,pharo
I would like to know which FFI interfaces are supported and functional in Pharo 4, which ones are recommended (if any), and if there are some big changes planned in the future Pharo versions. Especially I would like to know which stable FFI callback mechanism is available, and what are...

Pharo Smalltalk - How can I list all the classes in a Category (aka Package or Tag)?

smalltalk,pharo
Pharo Smalltalk - How can I list all the classes in a Category? In the System Browser, the first pane contains the Category under which all my classes are listed. Is there a list of those classes programmatically?...

animation in squeak smalltalk

smalltalk,pharo,squeak,morphic
I have a simple morph in squeak smalltalk. I want to move it from x1,y1 to x2,y2 (animation) with 5 seconds (or 10 seconds) is there a build in way to create animation in squeak smalltalk ?...

Image freeze when a continuation is called

crash,pharo,continuation
I'm trying to test the continuation facility in Pharo, with this code(in the playground): | cont f | f:=[ |i| i:=0. Continuation currentDo: [ :cc | cont:=cc ]. i:=i+1. ]. f value. "1" cont. "a Continuation" However, as soon as I call the continuation saved in cont(replacing cont. by cont...

Pharo punctuation marks [duplicate]

regex,pharo,punctuation
This question already has an answer here: Learning Regular Expressions [closed] 1 answer Is there any way to capture all the places in a String, where there are punctuation marks like '.,:;!?' Basically, am looking for a regex that captures all the above....

Pharo Smalltalk - Is there a way to force deallocation (dealloc) on an Object (instance) (expire sessions etc) during Seaside development?

smalltalk,pharo,seaside
When you want to garbage collect a certain instance, what message can you send it? I'm hacking away at a Seaside based app, and a lot of things ca go haywire, including my RootComponent having 10 instances (is this normal), and I'd like a fresh start (not a fresh image)...

In Smalltalk, how to select both strings and integers from an array

string,select,integer,smalltalk,pharo
Using Pharo, I have a collection e.g. array := #('up' '4' 'b'). and I'd like to use select: to create a collection that only includes the numbers, provided they're smaller than 20, and a specific string - in this case, 'up' and '4' I tried: array select: [:each | (each='up')...

Compiling Pharo to C?

compilation,smalltalk,pharo
It is said that Pharo's VM (CogVM) is developed, tested, profiled and etc in Smalltalk, but then the Smalltalk code is transcompiled to C, which is then compiled along side with some OS abstraction C code using the default system C compiler. Well, I'd like to do a similar thing,...

Error on importing FAMIX Java model using the VerveineJ

pharo,moose-technology
I'm trying to import a FAMIX JHotDraw java model using Verveinej, but no success so far. I'm facing a FAMIX.FileIndexedAnchor not found error. As far as I understood Moose is not finding the source files, am I right? So, where should I set the root source folder? Thanks in advance!...

Smalltallk - How can I get an Array (or Collection) of the all the Instance variables in an Object (the current Instance) of a Class?

smalltalk,pharo
Let's say we have a Class and we instantiate it, creating an Instance of that Class. This Instance has a number of (instance)variables, defined by the class, that I need to use. I'd like to get all these (instance)variables in an Array or some Collection so I can iterate through...

Pharo 4 FFI async callbacks

smalltalk,ffi,pharo
What are the options (if any) to handle asynchronous FFI callbacks in Pharo 4? By asynchronous I mean that callback gets invoked by foreign language library some time after the FFI function that sets the callback has finished and returned to Smalltalk. Example of NativeBoost callbacks in the image is...

How to set Pharo keyboard shortcut for switching windows?

pharo,morphic
I have read that in Pharo it's possible to switch between windows using Alt-Tab. But I've never been able to test this, because both OSes I commonly use capture Alt-Tab and use it for their own window switching. I can't find a listing for Alt-Tab in the system Keymap Browser....

Monticello - How do I install a package from an online repository (SmalltalkHub) in Pharo?

smalltalk,pharo,monticello
I can't seem to be able to figure out how to use Monticello with SmalltalkHub. I've used it before to manage local repositories. Did this: MCHttpRepository location: 'http://smalltalkhub.com/mc/BenComan/PointerDetective/main' user: '' password: '' When I opened the Monticello Browser there is no package on the left named PointerDetective. Do I need...

Pharo method with multiple arguments

pharo
I am creating a Pharo Class method that takes 3 arguments. I am using the following code and it gives me the error "Variable or expression expected.." MethodName: arg1:argValue1 arg2:argValue2 ^ self var1: argValue1 var2: self var3: argValue2 What would be the correct method declaration syntax? Later on, I intend...

trying to retrieve element from an OrderedCollection

smalltalk,pharo,squeak,gnu-smalltalk
I am using pharo. I have a Car class which has a speed variable and the class side method withSpeed: aSpeed which sets speed := aSpeed. I am trying the following test in the playground. car := Car withSpeed: 20. cars := OrderedCollection new. cars add: car. Now, I have...

How do I test for equality between an Array of associations and an Object (instance) in Pharo Smalltalk?

smalltalk,pharo
I have this small piece of code which doesn't seem to work and test weather the objects are one and the same. something := ((selectedTab value) == registerObject). or: ((selectedTab value) == registerObject) ifTrue: [ "this never get's executed" ] I've "Explored pointer" on both instances "selected value" has the...

Pharo - Image with Seaside in it is stuck, can't click on anything in the UI?

smalltalk,pharo
Pharo - Image with Seaside in it is stuck, can't click on anything in the UI? The app is fine, I can access it through the web interface. What can I do? It's an old Pharo 1.3 Seaside 3.0.7 developer image from here: http://www.seaside.st/distributions/Seaside-3.0.7-final.zip http://www.seaside.st/download/pharo Later edit: looking at http://localhost:8080/status...

Seaside jQuery - Sorting a list with drag and drop and sending it back via Ajax causes OrderedCollection to turn into an Array?

smalltalk,pharo
The code below is form the Seaside book at: http://book.seaside.st/book/web-20/jquery/enhanced-todo-application/drag-and-drop html jQuery new sortable onStop: (html jQuery ajax callback: [ :items | modelRole getModelRolePlayer setItemList: items ] passengers: (html jQuery this find: 'li')); axis: 'y' My instance variable _itemList is initially OrderedCollection. As soon as I move the rows around...

How does find-by-example work in the Pharo Finder?

smalltalk,pharo
One of the things I was most impressed with when digging into Pharo was that the Finder could do find-by-example. I'd previously only seen this in languages like Haskell, where it's possible to know for certain that a function has no side effects. How does Pharo manage to implement this...

Add path segment at last part of URL with ZnUrl

smalltalk,pharo
I am using Pharo 3 and I want to add a path segment as the last part of an URL for example http://example.com/myapp?key1=param1&key2=param2 and I want to get /myParam added to the last part. With ZnUrl I tried with #addSegment: (ZnUrl fromString: 'http://example.com/myapp?key1=param1&key2=param2') addPathSegment: 'myParam' but results in http://example.com/myapp/myParam?key1=param1&key2=param2 How...

Pointer Detective - Inspecting an Object (instance) and Doing a “PointerDetective openOn: self.” leads to a System Error in Pharo?

smalltalk,pharo,pointer-detective
Pointer Detective - Inspecting an Object (instance) and Doing a "PointerDetective openOn: self." leads to a System Error in Pharo? The object is a WhateverRoot instance (subclass of WAComponent) that has "canBeRoot ^true." Am I doing something wrong? PS. My "eagle eye" caught a typo on line 9 of the...

Smalltalk - Seaside, Magritte: “object description” giving “MessageNotUnderstood” exception

smalltalk,pharo,seaside
I am working through the Seaside Book (http://book.seaside.st/). I am currently busy with the chapter on Magritte. I followed the steps of the first example (http://book.seaside.st/book/advanced/magritte/first-examples) but when I try to inspect the object's description, I get the MessageNotUnderstood: Address >> descriptionStreet. |address| address := Address example1. address description. If...