Re: [Pharo-users] Morph Code problem

2020-03-22 Thread K K Subbu

On 22/03/20 11:20 AM, shawon58 wrote:

i am new in morph code. so i try this code "Color orange asMorph openInWorld"
. in my screen it shows a line but i cant able to close that. screen shot
added below. thanks



What you are seeing is a StringMorph containing the name of the color. 
Inspect just "Color orange asMorph" part to see it.


You can bring up a halo morph with Shift-Alt-click on it and then press 
'x' to delete it. If you find getting this halo difficult, imagine a box 
around the morph. Click somewhere outside, press shift and drag around 
it. You will now see a halo of buttons around it.


If you are trying to build a Morph with that color, try:

 Morph new color: (Color orange); openInHand

HTH .. Subbu



Re: [Pharo-users] Slots vs collections

2020-03-20 Thread K K Subbu

On 20/03/20 4:54 PM, N. Bouraqadi wrote:

Hi,

Suppose I have an instance variable referencing a collection of booleans.
I want to have all elements of the collection be stored as bits.
Is there a way I can express it using slots?


What do the bits represent? Is there an ordering among these booleans?

You could use a Set of integers (for ordinals) or symbols (for cardinals 
like flags).


HTH .. Subbu



Re: [Pharo-users] What is the difference between a form and a morph?

2020-02-23 Thread K K Subbu

On 24/02/20 10:37 AM, Steve Quezadas wrote:

 > A Form is a rectangular of pixel.
I don't understand. What is a "rectangular of a pixel"?


I meant rectangle of pixels. Sorry for the typo.

If you want to display a bitmap, you need to know its width x height x 
depth. This is what a Form provides. See http://wiki.squeak.org/squeak/697



 > You can create a Morph around a form with:
Don't you mean "convert  a [Form] to a [Morph] object"? What do you mean 
by "create a Morph around a form"?


No, you don't convert the form. You need a tool to see/edit/interact 
with this object which is what a morph allows you to do. See


  http://wiki.squeak.org/squeak/2305

See John Maloney's article for details on Morphic GUI.

HTH .. Subbu



Re: [Pharo-users] What is the difference between a form and a morph?

2020-02-23 Thread K K Subbu

On 24/02/20 2:00 AM, Steve Quezadas wrote:
[Morph], from what I understand, deals with manipulating graphics on 
smalltalk. But when I use ZnEasy to get a jpeg file, I notice that it 
returns a [Form] and not a [Morph] to display a jpeg. Spec2 also wants 
[Form] for displaying images rather than [Morph].


So what is the difference between a [Form] and a [Morph] since they both 
seem to deal with graphics?


A Form is a rectangular of pixel. Essentially, a picture. You can create 
a Morph around a form with:


  aForm asMorph openInHand.

A Morph is the basic unit of Morphic GUI - a live, direct editor of 
objects. An excellent short tutorial about it is at:


http://stephane.ducasse.free.fr/freebooks/collectivenbluebook/morphic.final.pdf

HTH .. Subbu



Re: [Pharo-users] Why Smalltalk is so easy to evangelize

2020-01-09 Thread K K Subbu

On 10/01/20 12:25 AM, Kasper Østerbye wrote:
This rant states once again that in Smalltalk everything is an object. 


The word 'object' has been bandied about with multiple meanings, so it 
is understandable that you would challenge this claim. Smalltalk uses 
the term 'object' with a specific meaning - see chapter 30 of bluebook 
(Formal Specification of Object Memory)[1] for a concrete definition.


The image is an object graph. The allocated memory in a heap consists 
entirely of a list objects which can be iterated through first/next 
messages.


You need only two tools - Inspector and Explorer. Inspect to examine a 
single object and the explorer to trace interconnections in the object 
graph.


Implementations like Squeak or Pharo may use strings instead of fully 
reifying programmable entities but that doesn't mean that they cannot. 
Also, some 'objects' may be managed entirely within the VM interpreter 
for pragmatic reasons.


To me, what really is nice about Smalltalk is NOT the language - it is 
the image and live programming. And I can get around all the problems 
with the language because of it. I miss:


Bingo! Smalltalk is best understood as a virtual machine with live 
programming facility. Language is only a small part of it.


[1] http://www.mirandabanda.org/bluebook/bluebook_chapter30.html

Regards .. Subbu



Re: [Pharo-users] Linux init script

2019-07-10 Thread K K Subbu

On 10/07/19 10:30 PM, Sebastián Filippini wrote:

Hello everyone,

I'm trying to write a Linux init script for a Pharo application. I'm 
using a bash script wrapper to launch pharo. This script executes the 
pharo script provided by get.pharo.org.


./pharo myapp.image start.st &
PID=$!
echo $PID > /var/run/myapp.pid


You could try direct exec instead of spawning a subshell. E.g.

echo $$ >/var/run/myapp.id
exec ./pharo myapp.image start.st

HTH .. Subbu



Re: [Pharo-users] Distribution of test method name length

2019-06-20 Thread K K Subbu
Nice graph, Ben! The larger test names (selector size > 100) look more 
like sentences than names ;-).


On 21/06/19 6:50 AM, Ben Coman wrote:
    classes := Object allSubclasses select: [ :cc | cc isKindOf: 
TestCase class ].

    methods := c flatCollect: [ :c | c allMethods  ].


Did you mean classes flatCollect: here?


    tests := methods select: [ :m | m selector beginsWith: 'test' ].
    lengths := tests collect: [ :m | m selector size ].


select:thenCollect: can also be used here.

    lengths asBag keysAndValuesDo: [ :len :count | Transcript crShow: 
len; show: ','; show: count  ]


I find the in: selector very handy for quick commands without having to 
use undefined temps. e.g.


(Object allSubclasses select: [ :cc | cc isKindOf: TestCase class ]) in: 
[ :classes |

(classes flatCollect: [ :c | c allMethods  ]) in: [ :methods |
			(methods select: [ :m | m selector beginsWith: 'test' ] thenCollect: 
[ :m | m selector size ]) in: [:lengths |
lengths asBag keysAndValuesDo: [ :len :count | Transcript crShow: 
len; show: ','; show: count  



Regards .. Subbu






Re: [Pharo-users] Creating a dictionary from a list of associations

2019-05-02 Thread K K Subbu

On 02/05/19 9:52 PM, Sven Van Caekenberghe wrote:

Dictionary withKeys: words andValues: (words collect: #size)

HTH .. Subbu


Never saw that one, cool.

But it is #newFromKeys:andValues: as far as I can see


You're right. I got mixed up. Thanks for the correction .. Subbu




Re: [Pharo-users] Creating a dictionary from a list of associations

2019-05-02 Thread K K Subbu

On 02/05/19 9:14 PM, Konrad Hinsen wrote:

| words lengths |
words := #('abc' 'defg').
lengths := Dictionary new.
words do:
   [ :each | lengths at: each put: each size ].


Dictionary withKeys: words andValues: (words collect: #size)

HTH .. Subbu



Re: [Pharo-users] Why doesn't the VM command line help show the useful image commands anymore?

2019-04-30 Thread K K Subbu

On 30/04/19 6:14 PM, Tim Mackinnon wrote:

Subbu - I didn’t understand your point? How would I know to do pharo
-- --list , by looking at the output of —help? (And in fact that
doesn’t work on OSX, it prompts me for an image - thus reinforcing my
point that the default image doesn’t appear to work, at least not in
osx).


Tim, I don't have access to Mac OSX :-(.

The usage text is printed in lines 296-301 in

https://github.com/pharo-project/pharo-vm/blob/master/opensmalltalk-vm/platforms/Mac%20OS/vm/sqMacUnixCommandLineInterface.c

If you don't see the same usage message, then it is a bug, possibly a 
missing macro def in the build script.


The platform startup code on Mac and Linux are similar. They both parse 
args for option words starting with single or double hyphens until a 
word which matches "*.image" or "--" is seen. Rest of the words are 
treated as a image (optional) and its arguments.


Regards .. Subbu



Re: [Pharo-users] Why doesn't the VM command line help show the useful image commands anymore?

2019-04-30 Thread K K Subbu

On 30/04/19 3:35 AM, Tim Mackinnon wrote:

Anyway - I tried using the command line on OSX ( I noticed they had
used pharo, and not pharo-ui — which I never understood: why is it
not pharo for ui and pharo-cmd for terminal, as it burns most
people?) - and typed “pharo —help”, and you get an impressive long
list of commands - however it doesn’t show you the useful Image
commands anymore? So you would never know to use “pharo Pharo.image
—list”.

A while back it showed you that - but its now gone which seems a
shame?


$ pharo --help

will pass the option --help to the VM, not the virtual image. You have 
to "Precede  by '--' to terminate VM options and begin the 
virtual image and its options.


$ pharo -- --list

will pass the --list to the default image - ${PHARO_IMAGE:-Pharo.image}


I also notice at the bottom of the list, its says the the image name
defaults to Pharo.image - however I haven’t noticed that works at all
- you have to specify an image, so thats a bit misleading.


$ PHARO_IMAGE=Pharo.image ./pharo -- eval 3+4
7
$ PHARO_IMAGE=Pharo.image ./pharo -- --help
Usage: [] [--help] [--copyright] [--version] [--list] [ 
--no-quit ]

--help   print this help message
--copyright  print the copyrights
--versionprint the version for the image and the vm
--list   list a description of all active command line handlers
	--no-quitkeep the image running without activating any other 
command line handler

 a valid subcommand in --list

Preference File Modification:
--preferences-file   load the preferences from the given 
	--no-default-preferencesdo not load any preferences from the 
default locations


Documentation:
A PharoCommandLineHandler handles default command line arguments and 
options.

The PharoCommandLineHandler is activated before all other handlers.
It first checks if another handler is available. If so it will activate 
the found handler.


$ PHARO_IMAGE=Pharo.image ./pharo -- --list
Currently installed Command Line Handlers:
FuelLoads fuel files
config  Install and inspect Metacello Configurations from 
the command line

saveRename the image and changes file
update  Load updates
printVersionPrint image version
st  Loads and executes .st source files
testA command line test runner
clean   Run image cleanup
get Install catalog projects from the command line 
(consult catalog at http://catalog.pharo.org)

evalDirectly evaluates passed in one line scripts

HTH .. Subbu



Re: [Pharo-users] How do you rotate a morph by degrees

2019-04-25 Thread K K Subbu

On 25/04/19 7:29 PM, Steve Quezadas wrote:
I am trying to rotate an instance of a [Transformation morph]. I am 
sending an "angle:" message, which should work since "angle:" is listed 
as a method in it's parent class, yet when I sent a message, it claims 
"it does not understand #angle". Shouldn't messagepassing forward the 
message to it's parent class?


Did you mean "TransformationMorph"?

I just tried the one-liner below in Pharo 7 (64b Linux) and it worked

(TransformationMorph new asFlexOf: ('Hello' asMorph)) angle: (Float pi / 
4); openInHand.


Regards .. Subbu



Re: [Pharo-users] difference between double dispatch and the method explains here

2019-04-06 Thread K K Subbu

On 06/04/19 4:49 PM, Roelof Wobben wrote:

Hello,

I just learned double dispatch.
And now for the Robot challenge of exercism Tim has pointed me to this 
article(https://blog.metaobject.com/2019/04/accessors-have-message-obsession.html) 


but I fail to see how the move method looks like in that article.
I had a conversation with Tim in the exercism channel and the way he 
explains it, it looks like double dispatch for me.


Am I on the right track or do I oversee something here.
unary methods like moveRight perform specific ops and are not 
parametric, so only a single dispatch, depending on the receiver, is needed.


If you change it to move: aDistanceOrAngle, then performing requests 
like "move: 3 cms" or "move: 30 degrees" will depend not only on the 
receiver but also on the class of the argument. This would need double 
dispatch (aka multiple polymorphism). The first dispatch would be based 
on the receiver and the receiver's method would then dispatch it based 
on the class of the argument (i.e. Distance>>move or Angle>>move )


HTH .. Subbu



Re: [Pharo-users] is this valid smalltalk

2019-04-04 Thread K K Subbu

On 04/04/19 4:46 PM, Roelof Wobben wrote:

Hello,

For a challenge of Exercism I need to check if some parenthes and 
brackets are balanced.


so for example

()  = true
([])  = true

but (])  is not true because the bracket has no opening bracket.

Now I wonder if I can premature end a #do:  like this

collection do: [:element | (condition with element) ifFalse: [^false]]


Have you looked at anySatisfy:

 #('the' 'quick' 'brown' 'fox') anySatisfy: [:s | s beginsWith: 'x' ]

Regards .. Subbu



Re: [Pharo-users] eval from the linux commandline

2019-03-24 Thread K K Subbu

On 24/03/19 5:23 AM, test email wrote:

i need to eval an object from my linux commandline. I understand that
 clap-st is able to do this, but I can't seem to import it into
pharo7, I suppose because of compatability reasons.

Someone sent me this, but I can't seem to replicate the help screen.
Is it because I'm on linux and he's on mac?


What exactly are you trying to evaluate? For simple expressions, I use:

$ ./pharo Pharo.image eval 20 factorial
243290200817664
$ alias p='./pharo Pharo.image eval'
$ p Morph allSuperclasses
an OrderedCollection(Object ProtoObject)
$ echo \'hello\' , \' world\' >hello.st
$ p $(< hello.st)
'hello world'
$

HTH .. Subbu



Re: [Pharo-users] Hmmm sending at:put: to an undefined object (nil) gives a confusing error message

2019-03-13 Thread K K Subbu

On 13/03/19 12:45 PM, Richard O'Keefe wrote:

Base 256: that's an implementation detail.
Little-endian: that's an implementation detail.


Architecture-specific no. Implementation yes. But that should be fine 
for private methods.



My Smalltalk uses base 65536 native-endian and
takes some care not to let Smalltalk code find out.
(Not least because on 64-bit machines I want to
use base 2**32.)


This would make it host-specific. Byte arrays are not host-specific.


For *private* methods, depending on otherwise
hidden implementation details is fair enough.
My Smalltalk picked up a convention from Squeak
-- or rather, from the Squeak mailing list --
that a 'pvt' prefix on a selector makes it truly
private and *enforces* that.  Pharo does not seem


pvt prefix is possibly inspired by Hungarian notation. I find that it 
impairs readability and maintenance. Should a method change from private 
to public or vice versa down the line, maintenance will be a nightmare. 
My own preference is placing them in 'private' category (or even 
private-* categories).



to have anything similar, and #at: is the epitome
of a selector in extremely wide general use.
Since #digitAt: exists -- and is what the integer
classes use -- it is practically certain that #at:
is sent to an integer only by mistake.


You make a good point here. Perhaps #at:/#at:put: should throw an error 
for all numbers and private methods could use basic versions instead.


Regards .. Subbu



Re: [Pharo-users] Hmmm sending at:put: to an undefined object (nil) gives a confusing error message

2019-03-12 Thread K K Subbu

On 12/03/19 9:25 AM, Richard O'Keefe wrote:

Squeak where (20 factorial at: 1) answers 0 (oh dear oh dear oh
dear).


Richard,

Could you please elaborate on why this is an error?

Large integers are place value encoded (base 256 little endian) and 
stored in byte arrays, so they need #at:/#at:put: (as private methods). 
Place value encoding is not architecture-specific so it doesn't affect 
portability of an image.


Regards .. Subbu



Re: [Pharo-users] Noob Question - slicing

2019-03-06 Thread K K Subbu
On Wed, 6 Mar 2019 at 12:00, Craig Johnson > wrote:



What is the simplest way to copy characters between positions 4 and
8 from a string in Pharo?


'1234567890' copyFrom: 5 to: 8 "5678"

Page 207 in Updated Pharo by Example book explains more on substrings.

HTH .. Subbu



Re: [Pharo-users] Interval form: x to: y when x > y - or how to count down...

2019-03-01 Thread K K Subbu

On 01/03/19 5:35 PM, Sven Van Caekenberghe wrote:

I like this too.

Why would this not happen ? It is just one selector more.

I think the only possible issue is that #to:do: is known by the
compiler, which makes it faster than any other iteration, even do: -
there is always a tradeoff between readability and raw speed.


Thank you for the kind words. I am not sure if speed would be affected 
much by:


downTo: stop
^self to: stop by: -1

downTo: stop do: aBlock
^self to: stop by: -1 do: aBlock

In performance critical paths, one can always use to:do: with explicit 
steps.


Regards .. Subbu



Re: [Pharo-users] Interval form: x to: y when x > y - or how to count down...

2019-02-28 Thread K K Subbu

On 28/02/19 6:33 PM, Tim Mackinnon wrote:


So I would expect “1 to: 0” to see:
1 -> 1
2 -> 0.


It is difficult for code to guess the intent of the coder. Did the coder 
intend an decreasing sequence or a stopping condition (i == end or i > 
end?). Perhaps, we could use an explicit selector:


  5 downto: 1

to disambiguate between the two cases.

Regards .. Subbu



Re: [Pharo-users] Why is #findString: in accessing?

2019-02-27 Thread K K Subbu




On 28/02/19 5:23 AM, Richard O'Keefe wrote:


It is surprisingly hard to keep categories consistent.  If there is
a way to say "here I am browsing method M in category G of class C,
is there an ancestor of C that puts the selector of M in a different
category?" I would love to know it.  (Adding such a code critic to
my Smalltalk is on the TODO list.)


Richard,

There is Browser>>#categorizeAllUncategorizedMethods that works this way 
in Squeak but for uncategorized methods.


But then, a tag-set would be more useful than just single 
categorization. It doesn't matter how accurate a category is, there will 
always be someone who will find an equally justifiable reason for 
putting a method into a different category ;-).


Is it possible to have a pragma or dummy method (say tags:) to list tags 
that could be extracted to facilitate searches? It should not have any 
runtime impact.


Regards .. Subbu



Re: [Pharo-users] [VIDEO TUTORIAL] How to use external code editors to code in Pharo

2019-01-24 Thread K K Subbu

On 24/01/19 9:47 PM, Sven Van Caekenberghe wrote:




On 24 Jan 2019, at 17:04, K K Subbu  wrote:

On 24/01/19 7:23 PM, Sven Van Caekenberghe wrote:

Everybody is of course totally free to do whatever they want,
but really, why the hell would you want to do that ?

Because text has many uses other than just feeding into a compiler
for translation to machine code? People who come from Unix/Linux
world are used to using a rich collection of tools that deal with
text in various ways.


I am myself a server/linux guy, an emacs user, I know what is all
possible and what the unix philosophy is.



No offense intended. Just wanted to point out that text can have 
different purposes. Historically, Smalltalk presented itself as a 
OS+IDE. Today, that is no longer true. Pharo is just a multi-platform IDE.



I also know how to integrate Pharo into that world, and this is super
important.

Thanks. This is what I intended to bring out.


You lose so much by doing that, I do not even know where to
start.


Live coding (i.e. coding in the presence of instances) is
undoubtedly more powerful than edit-compile-run cycle. Text is used
to direct IDE to edit live objects. But text has many more uses
than just issuing commands.  If beginners start using vim just to
edit code due to established habits, they will soon realize the
ease of live coding and remain in IDE. This is a self-correcting
error.


Well, I don't think so.
The users that you are going to attract in this way (the ones that
don't want to leave their own IDE/editor), will look at textual Pharo
and find it very strange and ill suited to textual editing (and they
are absolutely right), they will not discover the power, will not
learn (from this experience alone) what object
design/programming/power is, and will ask for more (e.g. give me ,
style compiler errors, better/easier structure of the file, fixed the
!! escape issue, etc, ...).


I am sure there will always be skeptics. But my own experience was 
different. For me, the most weird thing about Squeak (and now Pharo) IDE 
is its insistence in showing only one method at a time. A method is too 
small a chunk of code. It is easy to miss the forest for the trees. In 
Dimitris video, you see lots more code in one glance in vim session. So 
there are pragmatic reasons why some coders fallback to using fileOuts 
for browsing classes.


Regards .. Subbu



Re: [Pharo-users] [VIDEO TUTORIAL] How to use external code editors to code in Pharo

2019-01-24 Thread K K Subbu

On 24/01/19 7:23 PM, Sven Van Caekenberghe wrote:

Everybody is of course totally free to do whatever they want, but
really, why the hell would you want to do that ?
Because text has many uses other than just feeding into a compiler for 
translation to machine code? People who come from Unix/Linux world are 
used to using a rich collection of tools that deal with text in various 
ways.



You lose so much by doing that, I do not even know where to start.


Live coding (i.e. coding in the presence of instances) is undoubtedly 
more powerful than edit-compile-run cycle. Text is used to direct IDE to 
edit live objects. But text has many more uses than just issuing 
commands.  If beginners start using vim just to edit code due to 
established habits, they will soon realize the ease of live coding and 
remain in IDE. This is a self-correcting error.


Editing a .st file has always been possible, it is masochism.Vim is much more than just a typewriter. It can leverage a whole set of 
text-based tools. One could use it to auto generate methods, clean them 
up and then file into Pharo.


Regards .. Subbu



Re: [Pharo-users] [VIDEO TUTORIAL] How to use external code editors to code in Pharo

2019-01-24 Thread K K Subbu

On 24/01/19 4:40 PM, Dimitris Chloupis wrote:
Actually not only you can do it, its also very easy. So the following 
video tutorial explains in the first 3 minutes how to do this and then 
spends another 10 min talking about how this could be automated to be 
completely automatic and instantaneous.


https://youtu.be/3YfRhDafIxs


Nice clip - short and sweet. You may want to point people to about chunk 
file format in the description to alert people who may break chunk 
syntax by accident and get confused when fileIn breaks (been there, done 
that :-(). Also a caveat not to edit *.changes or *.sources though they 
look very similar to *.st files.


BTW, if the command is all in one line, you don't need to select it 
before doIt. It is implied. Even if it is spread over a couple of lines, 
just press SHIFT-HOME after finishing typing the text and use the arrow 
keys to select multiple lines and then doIt. Very nifty!


Regards .. Subbu



Re: [Pharo-users] rotating a morph through messaging

2018-12-31 Thread K K Subbu

On 31/12/18 1:54 AM, Steve Quezadas wrote:
I am experimenting with pharo right now, particularly with Morphs. The 
weird thing is that some morphs can have a rotation halo and others do not.


This has a "rotate halo":
bar := EllipseMorph new.
bar openInWorld.

This does not:
foo := Morph new.
foo openInWorld


A morph has to implement #prepareToRotate method for rotate Halo button 
to appear and also implement rotationDegrees: method to do the actual 
transformation. Otherwise, you can add a flex shell to the morph and 
request it to rotate it.


Morph does not support rotation, so there is no rotation button in its 
halo. EllipseMorph has a dummy rotationDegrees: method. CircleMorph and 
PolygonMorph go the whole way.


foo := Morph new addFlexShell openCenteredInWorld
foo topRendererOrSelf rotationDegrees: 45

bar := (PolygonMorph
vertices: {261@400. 388@519. 302@595}
color: Color blue
borderWidth: 2
borderColor: Color black) openInWorld.
bar rotationDegrees: 45

HTH .. Subbu



Re: [Pharo-users] Naming parameters - conventions?

2018-07-11 Thread K K Subbu

On Thursday 12 July 2018 03:54 AM, Tim Mackinnon wrote:

I was taught {“a”/“an”}DataType, so it would be:

#name: aString


It depends on the current level of abstraction. At the lowest levels, it 
is okay to use basic types like aString since classes (types) define 
behavior. If you are operating at a much higher level, say transfering 
money between two accounts, you would do:


#transferMoney from: aPayer to: aPayee

where both aPayer and aPayee could be anAccountHolder

Essentially, the idea to keep the message part as close to normal 
statements as possible.


The book "A Mentoring Course Smalltalk" by Andres Valloud covers this 
aspect in great detail.


Regards .. Subbu




Re: [Pharo-users] pharo bash script with startup

2018-06-27 Thread K K Subbu

On Wednesday 27 June 2018 06:39 PM, K K Subbu wrote:


The double quotes are required here to skip splitting arguments with 
embedded spaces into different words.


I suspect the error is earlier in the image=$@ assignment. This requires 
double quotes. Double quotes are also required while calling zenity to 
avoid word splitting.


My earlier fix is also in error, Sorry!

Essentially, we are mixing up single value variable (image) with 
argument array ($@). I found a cleaner fix :



if [ $# -eq 0 ]; then
image_count=`ls "$RESOURCES"/*.image 2>/dev/null |wc -l`
if [ "$image_count"  -eq 1 ]; then
set -- "$RESOURCES"/*.image
elif which zenity &>/dev/null; then
		set -- "$(zenity --title 'Select an image' --file-selection --filename 
"$RESOURCES/" --file-filter '*.image' --file-

filter '*')"
else
set -- "$RESOURCES/Pharo6.1-64.image" 
fi
fi

# execute
exec "$LINUX/pharo" \
--plugins "$LINUX" \
--encoding utf8 \
-vm-display-X11 \
"$@"


HTH .. Subbu



Re: [Pharo-users] pharo bash script with startup

2018-06-27 Thread K K Subbu

On Wednesday 27 June 2018 01:08 PM, Otto Behrens wrote:

I am running with an absolute image path.

The issue is definitely exec "$image" in the script. If I remove the
"", i.e. exec $image, then it works.


The double quotes are required here to skip splitting arguments with 
embedded spaces into different words.


I suspect the error is earlier in the image=$@ assignment. This requires 
double quotes. Double quotes are also required while calling zenity to 
avoid word splitting.


Also, the image_count should be checked before calling zenity.

Can you try with this version?


if [ $# -eq 0 ]; then
image_count=`ls "$RESOURCES"/*.image 2>/dev/null |wc -l`
if [ "$image_count"  -eq 1 ]; then
image="$RESOURCES"/*.image
elif which zenity &>/dev/null; then
		image="$(zenity --title 'Select an image' --file-selection --filename 
"$RESOURCES/" --file-filter '*.image' --file-filter '*')"

else
image="$RESOURCES/Pharo6.1-64.image"  
fi
else
image="$@"
fi

# execute
exec "$LINUX/pharo" \
--plugins "$LINUX" \
--encoding utf8 \
-vm-display-X11 \
"$image"


HTH .. Subbu



Re: [Pharo-users] Morph & MVC tutorials

2018-06-06 Thread K K Subbu

On Thursday 07 June 2018 03:07 AM, Matias Maretto wrote:
Hi guys, I have been doing some things with Dolphin, actually feel very 
confortable with it, but now I am trying to learn Pharo. I have noticed 
that many things are quite similars,  but others are very differents, 
one of this things is the Visual Part, can someone point me out some 
good tutorial for Morph and MVC, I trying to understand the use of these 
s two "worlds" and I want to "play" a little with them.


MVC is a dated GUI framework. Morphic is a live and direct graphical 
programming framework. A good place to start is chapter 5 in:


 https://github.com/SquareBracketAssociates/UpdatedPharoByExample

The original paper(?) by John Maloney and Randy Smith is at:


http://web.media.mit.edu/~jmaloney/papers/DirectnessAndLivenessInMorphic.pdf

and a tutorial exploring the basic concepts is at:

http://sdmeta.gforge.inria.fr/FreeBooks/CollectiveNBlueBook/morphic.final.pdf

HTH .. Subbu



Re: [Pharo-users] Pharo IDE - change mouse cursor color/size

2018-01-30 Thread K K Subbu

On Tuesday 30 January 2018 01:06 PM, Norbert Hartl wrote:
Am 30.01.2018 um 08:26 schrieb "p...@highoctane.be 
" >:
On Tue, Jan 30, 2018 at 12:12 AM, Torsten Bergmann > wrote:



Cursor>>beCursor with Cursor being a Form makes a lot of sense on any 
platform.



Sorry but Cursor>>beCursor does not make any sense on any platform :P

Could you be more explicit?

If beDisplay makes sense for DisplayScreen why not beCursor for Cursor? 
While a Cursor can be emulated in an image, it would be more efficient 
to use the cursor support present in practically all graphics 
controllers these days.


TIA .. Subbu



Re: [Pharo-users] Pharo things analog reads ?

2017-12-19 Thread K K Subbu

On Wednesday 20 December 2017 03:50 AM, Steven Costiou wrote:

So connecting an Arduino-like device to the raspberry that is
configured as an i2c slave, Pharo can ask for analog values. I will
try tomorrow with analog sensors, I will share if i manage to build
nice examples.

Seems to be even easier using a special chip: 
https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi?view=all


An Arduino would be an overkill. Also, there is no need for bitbanging. 
MCP3008 is are directly supported by the IIO subsystem and its channel 
data is demuxed in /sys/bus/iio/devices/iio:device


http://www.jumpnowtek.com/rpi/Using-mcp3008-ADCs-with-Raspberry-Pis.html

HTH .. Subbu



Re: [Pharo-users] Embedded PDF viewer?

2017-11-13 Thread K K Subbu

On Monday 13 November 2017 05:29 PM, Ben Coman wrote:
Yes, I've certainly considered it.  Pragmatically, in my electrical 
career I deal with a lot of single page A3 PDF scans of schematic 
drawings, so pre-converting to a bitmap format outside of Pharo wouldn't 
lose much.


PDF deals with vector graphics, so bitmap conversion will be lossy. You 
could import them as SVG instead use the existing classes for handling 
SVG and XML.


HTH .. Subbu



Re: [Pharo-users] Embedded PDF viewer?

2017-11-13 Thread K K Subbu

On Monday 13 November 2017 09:50 AM, Ben Coman wrote:
I've managed to build PDFium into a shared library on Ubuntu 16.04.  
(I'll announce a blog post on this later.)
Now I'm considering the best bitmap format to bring the rendered page 
back into Pharo.


Have you considered importing PDFs as a sequence of compressed PNGs into 
Pharo? If you not interested in twiddling pixels in the imported PDFs, 
perhaps PNG may be sufficient. They take up lesser space and easier to 
move around or re-export.


Regards .. Subbu



Re: [Pharo-users] Why do we separate class/instance methods in the browser?

2017-07-24 Thread K K Subbu

On Sunday 23 July 2017 08:34 PM, Tim Mackinnon wrote:

I find it a straight jacket that we have to click that class button
just because we want to write what is effectively a constructor that
occurs to us when we are writing an instance method. Its very jarring
and breaks your flow to “switch mode” to type one in.


You raise an important issue here. At the time of subclassing, we 
separate variables into instanceVariableNames and classVariableNames, 
but not with method selectors :-(. Separate tabs or panels (instance, 
class) may be a better way to display these methods.


This quirk pops up in textual mode too. "Foo" alone refers to a class 
but "Foo>>bar" refers to a instance side method and we have to use "Foo 
class>>bar" to refer to the class side method.


Regards .. Subbu



Re: [Pharo-users] Why do we separate class/instance methods in the browser?

2017-07-22 Thread K K Subbu

On Saturday 22 July 2017 06:51 PM, Tim Mackinnon wrote:


The one that stuck out for me (and is actually mentioned in another
thread this week) was the class/instance method difference. They
conceptually understood the difference coming from other languages
but our UI is tricky to understand with the Class button toggle we
have, and if you get methods on the wrong side, like with a test,
it's quite confusing.


It is an easy mistake to make and I have often seen this confusion in 
beginners. With the attention on the methods panel and text input, it is 
easy to overlook the class toggle button :-(.


An easy fix is to switch background color to differentiate between class 
and instance methods in both code and input panels. A better way would 
be to use tabs (like in Inspector).


BTW, I use the metaphor of toys (objects), moulds (classes) and mould 
factory (metaclass). A mould is an object from the perspective of the 
mould maker. Therefore operations on classes are 'methods' from the 
maker's perspective (note the recursion!).



Anyway - this got me thinking - why do we bother having a toggle in
our UI for this these days? Of course we know there is a class and a
metaclass but given that we have icons for methods now (and also have
a Protocol pane ) why don't we just show all the methods we have in
one list and let you filter them or even see them all? It seems much
easier and way more efficient to rapidly code this way.


This perspective comes from the traditional way - code and compile. In 
Pharo, we code one method at a time and sources are held in an external 
file and a pointer stored in each method, so displaying all methods in 
one panel would result in multiple file reads.



The only question then would be how to create methods of the right
type - whether to have a button to create the right template (and put
the  browser code pane in the right context) or whether to indicate
it by convention of the method name when creating it like + new:
aSize etc. (Or even: class new: aSize etc).

The more I think about it, the more it seems like something we should
consider trying both for making ourselves more efficient (I'll bet
everyone has written a method on the wrong side by mistake) and also
helping newcomers.


Such mistakes are part of the learning curve and decrease with time.

Regards .. Subbu



Re: [Pharo-users] How to calculate someone's age elegantly? Does Duration work?

2017-07-21 Thread K K Subbu

On Friday 21 July 2017 03:01 PM, Tim Mackinnon wrote:
Actually that simplification doesn’t work - someone born on 1/Mar/2000 
should be 11 on 1/Mar/2011 and this answers 10 (the previous version did 
work).


You're right. The simplification does not take into account leap days. 
Mea culpa. Original code (dropping +1) is readable and simple.


Regards .. Subbu

This does make me think its tricky enough to put this in the core - I 
may submit it along with the unit tests I borrowed from Stack Overflow 
(the shame)…


Its a good problem though. Thanks for discussing it with me.

Tim

On 21 Jul 2017, at 10:09, K K Subbu <kksubbu...@gmail.com 
<mailto:kksubbu...@gmail.com>> wrote:


^aDate year - self year -
(aDate dayOfYear < self dayOfYear) ifTrue: [ 1 ] ifFalse: [ 0 ])







Re: [Pharo-users] How to calculate someone's age elegantly? Does Duration work?

2017-07-21 Thread K K Subbu
I suppose no one needed it that badly ;-). Age is the difference in 
years except when the given date's julian is less than self's julian 
when it is less by 1, so the code can be simplified to:


^aDate year - self year -
 (aDate dayOfYear < self dayOfYear) ifTrue: [ 1 ] ifFalse: [ 0 ])

BTW, the code has an off-by-one error. +1 should be dropped in first age 
assignment.


Regards .. Subbu

On Friday 21 July 2017 12:55 PM, Tim Mackinnon wrote:

Yes that's a good solution, however I'm really surprised that with the plethora 
of dates, durations, timespans (we are well served with a very rich time and 
date domain) that this isn't already in the image?

It seems very surprising. In fact the group I was working with (other language 
programmers) kept looking and looking for something as they felt certain they 
had overlooked it given all those promising classes.

I'm curious why it's not in there? And would we also expect to find its 
equivalent on a timespan (maybe delegating back to this date method? This 
assumes that timespan can be fixed as it loses precision unexpectedly).

Thanks for the reply.

Tim



Sent from my iPhone


On 21 Jul 2017, at 06:41, K K Subbu <kksubbu...@gmail.com> wrote:

Date>>ageOn: aDate
" assert: (self <= aDate)
| age |

age = aDate year - self year + 1.
aDate monthIndex < self monthIndex ifTrue: [ ^age - 1 ].
(aDate monthIndex = self monthIndex and: [aDate dayOfMonth < self dayOfMonth]) 
ifTrue: [ ^age - 1 ].
^age

HTH .. Subbu


On Friday 21 July 2017 05:28 AM, Tim Mackinnon wrote:
Hi - I just ran a great MobProgramming session with Smalltalk for the XProLo 
group - and there was lots of great feedback and questions, however one of them 
really got me thinking…
We did a little exercise to create a Person class with name, dob - and then we 
TDD’d an age method… which seems simple on the surface but it gets to an 
interesting point - what about leap years? How old is someone on those years?
I thought that our plethora of Date/Duration classes might handle this - but I 
couldn’t spot something obvious and was wondering if someone had a neat answer.
Essentially if you try:
age
^Date today - self dob
You get a Duration,
But there isn’t :
^(Date today - self dob) asYears
There is is asDay
^(Date today - self dob) asDays
But then can you really
^(Date today - self dob) asDays / 365) truncated
But what about leap years… so
^(Date today - self dob) asDays / 365.25) truncated
It all feels a bit inelegant and I suspect there is a better Smalltalk way that 
is eluding me? Any suggestions?
Tim











Re: [Pharo-users] How to calculate someone's age elegantly? Does Duration work?

2017-07-20 Thread K K Subbu

Date>>ageOn: aDate
" assert: (self <= aDate)
| age |

age = aDate year - self year + 1.
aDate monthIndex < self monthIndex ifTrue: [ ^age - 1 ].
(aDate monthIndex = self monthIndex and: [aDate dayOfMonth < self 
dayOfMonth]) ifTrue: [ ^age - 1 ].

^age

HTH .. Subbu

On Friday 21 July 2017 05:28 AM, Tim Mackinnon wrote:

Hi - I just ran a great MobProgramming session with Smalltalk for the XProLo 
group - and there was lots of great feedback and questions, however one of them 
really got me thinking…

We did a little exercise to create a Person class with name, dob - and then we 
TDD’d an age method… which seems simple on the surface but it gets to an 
interesting point - what about leap years? How old is someone on those years?

I thought that our plethora of Date/Duration classes might handle this - but I 
couldn’t spot something obvious and was wondering if someone had a neat answer.

Essentially if you try:

age

^Date today - self dob

You get a Duration,

But there isn’t :

^(Date today - self dob) asYears

There is is asDay

^(Date today - self dob) asDays

But then can you really

^(Date today - self dob) asDays / 365) truncated

But what about leap years… so

^(Date today - self dob) asDays / 365.25) truncated


It all feels a bit inelegant and I suspect there is a better Smalltalk way that 
is eluding me? Any suggestions?

Tim






Re: [Pharo-users] Using the Debugger to write code

2017-07-12 Thread K K Subbu

On Wednesday 12 July 2017 08:33 AM, horrido wrote:

But for the life of me, I can't figure out how to create new classes for my
application from within the Debugger. Must I create new classes using the
System Browser first before I can continue adding new methods from within
the Debugger? What's the recommended procedure for all this?


Not necessarily. In Pharo, everything happens through message sends.
Classes are created by sending any one of subclass:* family of messages 
to the parent class. System Browser makes it convenient by adding a 
template to its bottom text panel. Magic happens in the subclass:* 
message sends.


When you "inspect" an object in the Debugger, a text panel will open up 
along the right side where you can type in a command just like in System 
Browser and "doIt". E.g. to create a subclass from Object.


   Object subclass: ...

HTH .. Subbu



Re: [Pharo-users] Can not save the source file

2017-06-16 Thread K K Subbu

On Friday 16 June 2017 05:38 PM, Marc Hanisch via Pharo-users wrote:

-rw-rw-r-- 1 marc marc43775 Jun  9 15:47 PharoDebug.log


You may want to check this log for error messages .. Subbu



Re: [Pharo-users] Help in thinking about how to save a "program"

2017-06-12 Thread K K Subbu

On Monday 12 June 2017 04:52 AM, Glenn Hoetker wrote:

I”m crafting a short program to help me process a large text file
(specifically: extract, sorting, and regularizing the “keyword” fields
of a large BibTex file). Especially since I don’t really know what I’m
doing, working in a Playground has been a great development environment.
 Now that the program is complete (under 30 lines, wonderful), I want to
be able to save it for future reference (and perhaps for future use).
 If I’d written a shell script, I’d just save “fixBibDeskKeyWords.sh” to
a directory. I’m not sure what to do in the Pharo environment, thought.


Playground saves your scripts in pharo-local/play-cache folder. Use 
Tools->File Browser to look in play-cache/ or pharo-local/play-cache/ 
folder. You will find all your playground scripts saved in *.ph files. 
Note down this name (or rename it to something easy to remember) and 
make a copy. Pass this file as an argument:


$ ./pharo Pharo myscript.st

BTW, Playground is just that and a file is for unstructured stream of 
bytes. You may want to start using System Browser to create classes and 
methods, tests etc. for code worth preserving. Pharo offers you a lot of 
services like live debug, cross-refs, tracking changes, packaging etc. 
It is a lot easier than you think ;-).


HTH .. Subbu



Re: [Pharo-users] Windows equivalent of kill -s SIGUSR1?

2017-05-14 Thread K K Subbu

On Monday 15 May 2017 02:47 AM, Alistair Grant wrote:

The subject pretty much says it all: Is there an equivalent on Windows
to the linux

kill -s SIGUSR1 

that gets the VM to dump its current status?


signals is unix-specific IPC. On Windows, you should be able to "create 
dump file" from right-click menu on Task Manager's process list (if you 
have the perms, of course!).


If you do a lot of system work on windows, sysinternals suite could be 
very useful. It has many utilities for advanced operations (Procdump?) 
on processes and files.


HTH .. Subbu



Re: [Pharo-users] [Ann] Pharo Sprint App to improve coordination during Pharo Sprints

2017-04-24 Thread K K Subbu

On Monday 24 April 2017 08:00 PM, Juraj Kubelka wrote:


Please, can you send me a screenshot? Or submit the screenshot
here https://github.com/JurajKubelka/PharoSprint/issues/new


Done. I think the error appears because when a login fails, the message 
causes a horiz scroll bar to be added to the panel pushing the fields 
beyond the top edge. I stumbled on this error because I tried using my 
fogbugz id whereas the login field needs the registered email id for login.


Regards .. Subbu



Re: [Pharo-users] [Ann] Pharo Sprint App to improve coordination during Pharo Sprints

2017-04-24 Thread K K Subbu

On Sunday 23 April 2017 08:43 PM, Juraj Kubelka wrote:


As the Pharo Sprint is organized in several places around the world, we
miss the connection with other guys. For that reason we decided to move
the physical whiteboard to the internet and developed Pharo Sprint App.


Excellent idea and a very useful tool! It took me just a few minutes to 
download it and post my first fix through it.


What would be workflow for using this app? Is this only for Pharo Sprint 
participants or can others also use it?


I faced a minor problem in the UI. The top half of login/password text 
input fields got clipped by title bar, when I opened it up first. Later 
the Update/Logout buttons also have their top border clipped off.


Regards .. Subbu



Re: [Pharo-users] Pharo 6 snap install

2017-04-15 Thread K K Subbu

On Friday 14 April 2017 03:39 PM, Luke Gorrie wrote:


- The latest Pharo VM source release is compatible with the latest Pharo
image.


This is too strong a condition. For the OS, an image is just a 
filesystem within a file. It is sufficient if the VM does not use the 
same executable name if it cannot execute the same image. After all, the 
VM is a machine and is not likely evolve as rapidly as the image it 
runs. If it cannot handle an image format then it should not reuse that 
VM's name.


Linux already supports binfmt_misc fs to handle such images. VMMaker can 
generate magic(5) file in addition to src/* files from which package 
post-installers can register multiple interpreters in 
/proc/sys/fs/binfmt_misc/. Python and Qemu use this to run different 
bytecode and instruction sets.


BTW, I am attaching a magic pattern file generated automatically from 
ImageFormat class in VMMaker image to illustrate my point.


Regards .. Subbu
# Smalltalk image file formats
0   lelong  6502Smalltalk image V3 32b  (%d)
!:mime application/squeak-image
0   belong  6502Smalltalk image V3 32b  (%d)
!:mime application/squeak-image
0   lelong  6504Smalltalk image V3 32b +C (%d)
!:mime application/cog-image
0   belong  6504Smalltalk image V3 32b +C (%d)
!:mime application/cog-image
0   lelong  68000   Smalltalk image V3 64b  (%d)
!:mime application/squeak64-image
4   belong  68000   Smalltalk image V3 64b  (%d)
!:mime application/squeak64-image
0   lelong  68002   Smalltalk image V3 64b +C (%d)
!:mime application/cog64-image
4   belong  68002   Smalltalk image V3 64b +C (%d)
!:mime application/cog64-image
0   lelong  6505Smalltalk image V3 32b +C+NF (%d)
!:mime application/cog-image
0   belong  6505Smalltalk image V3 32b +C+NF (%d)
!:mime application/cog-image
0   lelong  68003   Smalltalk image V3 64b +C+NF (%d)
!:mime application/cog64-image
4   belong  68003   Smalltalk image V3 64b +C+NF (%d)
!:mime application/cog64-image
0   lelong  6521Smalltalk image Spur 32b +C+NF (%d)
!:mime application/spur-image
0   belong  6521Smalltalk image Spur 32b +C+NF (%d)
!:mime application/spur-image
0   lelong  68019   Smalltalk image Spur 64b +C+NF (%d)
!:mime application/spur64-image
4   belong  68019   Smalltalk image Spur 64b +C+NF (%d)
!:mime application/spur64-image
0   lelong  68021   Smalltalk image Spur 64b +C+NF+Tag (%d)
!:mime application/spur64-image
4   belong  68021   Smalltalk image Spur 64b +C+NF+Tag (%d)
!:mime application/spur64-image



Re: [Pharo-users] Pharo 6 snap install

2017-04-12 Thread K K Subbu

On Wednesday 12 April 2017 07:33 PM, Alistair Grant wrote:

Hi Everyone,

I've made a snap package for Pharo 6 which I think is far enough along
for some wider testing.


Just tried it now. worked like charm.


--classic - Snap packages are normally sandboxed for security
 reasons.  Since Pharo is a development environment
 in which we want to be able to run any executable,
 or load any library, it is installed with access to
 the entire system (as the running user).

Is this really necessary even if we want to work only within an image?

Regards .. Subbu