squeak

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

不想你离开。 提交于 2019-12-17 20:13:49
问题 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 Why should I not do that? 回答1: Note: The following is implementation dependent. The ANSI Smalltalk Standard defines: It is unspecified whether the values of identical literals are the same or distinct objects. It is also unspecified

How one deals with typedefs in Squeak FFI

拟墨画扇 提交于 2019-12-13 02:04:38
问题 I want to interface with a library (HDF5) which uses exclusively its own typedefs in both function prototypes and structure definitions. typedef struct { H5L_type_t type; /* Type of link */ hbool_t corder_valid; /* Indicate if creation order is valid */ int64_t corder; /* Creation order */ H5T_cset_t cset; /* Character set of link name */ union { haddr_t address; /* Address hard link points to */ size_t val_size; /* Size of a soft link or UD link value */ } u; } H5L_info_t; In Visualworks

In Squeak, how to wrap every method send?

女生的网名这么多〃 提交于 2019-12-12 20:20:47
问题 I created a class, and in that class I have a method 'sendMessage: to: withArgs:' which recieves an object, a message and an array of arguments. The method is used to send messages to object and perform some algorithm. To use this method I have to create an instance x of the class I created and do something like x sendMessage: '+' to: '7' withArgs: '#(5)'. The result of this sending the message '+' to the object 7 with the parameter 5, plus some stuff that my algorithm does. But what I want

How do you compress a directory in Squeak Smalltalk?

纵饮孤独 提交于 2019-12-12 12:21:19
问题 How do you compress a directory in Squeak Smalltalk? I found the compressFile method in StandardFileStream but I can't figure out how to compress multiple files or a directory. I experimented with the System-Compression classes but haven't had much luck. Thanks in advance! This is what I have now. I'm adding time stamps at the end of file names, so here I want to put all files that begin with the given file name into a zip or gzip file. compressFile: aFileName in: aDirectory | zipped buffer

How can I parse character in a File in Squeak4.1?

ⅰ亾dé卋堺 提交于 2019-12-12 06:13:34
问题 friend, suppose I have a file test.txt, the content of file is "1+2*3", if the fomular directly expressed in Squeak's Workspace, print it will result 9 , What I want to get is 7 then I read the file content 1+2*3 from a file. code like this and it works well ReadFrom "read the equation from ./formular.txt" | fileContents | fileContents := FileStream readOnlyFileNamed: 'test.txt' do: [:f | f contents ]. ^fileContents. but how can I store the 5 caracters of string "1+2*3" into a collection ,

Keyword messages in smalltalk (Beginner)(Pharo)

五迷三道 提交于 2019-12-11 13:38:36
问题 I am trying to create a keyword message style method, but I can't figure out how to access the Receiver from inside the method. I am sure this is simple, however I can't find the answer anywhere. What I am trying to implement is redundant, but I would still like to know how it works. subst: i1 by: i2 ^ self copyReplaceAll: i1 with: i2. It would be called in the workspace as follows: string1 := 'Lemon'. string2 := 'm'. string3 := 'ss'. string1 subst: string2 by: string3. Error msg:

How to display the contents of a dictionary in a morph in smalltalk?

荒凉一梦 提交于 2019-12-11 12:48:39
问题 Because I don't seem to be able to find some predefined Morph that can display the contents of a Dictionary , I decided I'd better stop looking and wanted to create my own Morph . I found a nice description how to start with some nice example code to get me started, but quite soon I got to the problem that I don't seem to manage to draw text or anything like that on a canvas. I created a class Morph subclass: #DictionaryView instanceVariableNames: 'dictionary' classVariableNames: ''

Smalltalk dictionary as calculator

匆匆过客 提交于 2019-12-11 04:20:53
问题 I'm working on a homework assignment that asks us to create a type of Units class that can keep track of units and perform basic arithmetic on them. The problem description has this bit, which I don't completely understand: Probably the easiest way to keep track of the units is to give Units a dictionary that maps symbols to integers. If you are dividing by a unit then it has a negative value in the dictionary. You add two Units together by adding the value together for each symbol in the

How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects changes of the variable?

一世执手 提交于 2019-12-10 09:33:05
问题 I have an object with a variable containing a String. I have a window containing a LabelMorph/TextMorph (or some other Morph that displays Text?). How do i bind the LabelMorph/TextMorph to the variable, so that the label updates when the String in the variable changes? classic Smalltalk-80 dependent/change/update mechanism? Pharo Announcement framework? something different?? How would i do this? Which Morph should i use? 回答1: Depends on what you want to achieve. You might want to take a look

Implementation Strategies for Object Orientation

核能气质少年 提交于 2019-12-10 02:36:37
问题 I'm currently learning Smalltalk in the Squeak environment and I'm reading "Squeak - A Quick Trip To ObjectLand". I enter the object-oriented paradigm with some prior knowledge from Python and Java and this sentence from the book on page 36 has made me think: Smalltalk is a class-based implementation of an object-oriented language. Short sentence but very interesting. In OO all terms like class, object, instance seem to be well-defined and seem to point to the one and only true meaning and