smalltalk

Is it possible to extend an individual object in Smalltalk

烂漫一生 提交于 2019-12-18 03:36:27
问题 I'm doing research in Smalltalk reflection, and I was wondering if it was possible to extend an individual object like that would be possible for instance in Ruby. With this I mean a selector that only particular objects respond to. Here is some Ruby code that states what I mean. For clarification: in Ruby this open a virtual class for this object, and extends it with a new definition. The vital part here is that nothing changes to the class definition! o = Object.new o.instance_eval {def foo

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 to convert a number to a string in Smalltalk (visual works)

自作多情 提交于 2019-12-13 16:26:27
问题 I am having difficulty finding information on how to get a string representation of a number in Cincom Smalltalk. How is this performed in this language? Specifically I'm composing a string representation of an object, similar to the toString function in Java. 回答1: The printString method is meant to return a string to allow a programmer to interpret the number. If you used 3.14d in your example (a Double), you would see the 'd' character in the printString. This is fine for developers but if

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

Display an image from URL

╄→гoц情女王★ 提交于 2019-12-13 01:53:57
问题 I need get an image from a URL and display in a view. How can do this in Cincom Smalltalk? For example, I have this image URL: http://news.bbcimg.co.uk/media/images/64001000/jpg/_64001280_63976026.jpg And I wish display the image. I try: |req content reader| req := HttpRequest get:'http://news.bbcimg.co.uk/media/images/64001000/jpg/_64001280_63976026.jpg' asURI. content:=req execute. reader := JPEGImageReader new. reader from: content byteSource. But it doesn't work. Cincom Smalltalk says:

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 to access and use Java library/package in Smalltalk

大憨熊 提交于 2019-12-12 16:14:12
问题 It was mentioned in comments on another Stackoverflow question that it may be possible to access Java packages from Smalltalk. However, I have not been able to find any information regarding this on searching the net. Any insight in this regard will be highly appreciated. 回答1: Essentially there three ways to (re)use Java code in Smalltalk/X: Implement / port bindings to Java using JNI as Victor suggested. While not ported to Smalltalk/X, this has been done by Johan Brichau et al. - search for

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

Pharo Smalltalk - How can I check if a message conforms to a protocol defined in another object's Class?

和自甴很熟 提交于 2019-12-12 10:58:22
问题 I'm looking at this form an Objective-C background so be gentle. The experiment looks like this: Object1 has an instance variable named delegate. Object1 receives a message and the proceeds to check if delegate implements a specific protocol (whose name is known beforehand), if it does, then it checks if the message is among the protocol's implemented methods. It then makes a decision on how to interact with the delegate and so on. In Objective-C one has to define clear Protocols, usually

Smalltalk Learning Project: Any recommendation? [closed]

霸气de小男生 提交于 2019-12-12 07:49:01
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . Currently I am learning Smalltalk. I do this because I want to learn as much as I can in one week about a new programming language in order to improve my skills. Next week I will try something else. So far I am able to read Smalltalk code but I have a very limited experience