I am trying to introduce some PHP developers Smalltalk.
I seem to remember that the old Pharo website had a link to a Pharo Smalltalk Quick Reference card. If you printed it out it would print on a 8.5 x 11 page - front and back. I can't seem to find this link anymore. Does anyone know where to find this?
This post is probably what you are looking for. It seems unclear who the original author is or which version (there seem to be multiple ones) is the original one. See also this thread on the pharo-dev mailing list for a recent discussion on the topic (you'll find more references in that thread).
I'm copying the postcard code from that post here for completeness:
exampleWithNumber: x
"A method that illustrates every part of Smalltalk method syntax
except primitives. It has unary, binary, and keyboard messages,
declares arguments and temporaries, accesses a global variable
(but not an instance variable), uses literals (array, character,
symbol, string, integer, float), uses the pseudo variables
true, false, nil, self, and super, and has sequence, assignment,
return and cascade. It has both zero argument and one argument blocks."
| y |
true & false not & (nil isNil) ifFalse: [self halt].
y := self size + super size.
#($a #a "a" 1 1.0)
do: [ :each |
Transcript show: (each class name);
show: ' '].
^x < y
I think you are referring to Flyer Cheat Sheet
They sure love to brag about that postcard, but heaven help finding anything but a blurred .png version of it on their website!
Here's the double-sided Pharo Smalltalk cheat sheet / quick reference:
2018 version (pdf)
2013 version (pdf)
P.S. This is from where I found them, in case there is an updated version in the future.
Related
I'm trying to make a "very simple" syntax highlight for "cottle" (which is a script language used in a text-to-speech app dedicated to Elite:Dangerous).
All i want (at least at the beginning) is to have three different colours: Comments, "non-strings", and strings.
I started trying with the ST3 wiki, youtube tutorials, questions here.... but i can't sort out how to do it, 'cause the way the language work.
I'll try to show you an example
{ everything_between_a_pair_of_brackets_is_code }
everything outside all pairs of bracket is a string {_ and this is a comment. It begins with "_" and ends at the closing bracket }
{ This_is_code("but this is a string")
This_is_still_code("this is also a string {but_this_is_code(\"and a string\")} and this the end of the string")
}
My problem is how to define this kind of "nidification" in my cottle.sublime-syntax file. I managed to get the comment, but only the first one.
- EDIT -
This is a real script:
{event.item}
{if event.repairedfully:
fully repaired
|else:
partially repaired
{Occasionally(2,
cat(
OneOf("to ", "at "),
Humanise(event.health * 100),
" percent functionality"
)
)}
}
{Occasionally(2,
cat(OneOf(", ", "and is"), " ready for re-activation")
)}.
The output of this script could be "Engine module fully repaired." or "Engine module partially repaired, and is ready for re-activation."
Please note the last dot of the phrase, which in the code is after the last bracket.
This is another sample, with strings passed to functions inside other strings:
{OneOf("{ShipName()} has", "")}
{OneOf("left supercruise", "{OneOf(\"entered\", \"returned to\", \"dropped to\")} normal space")}
My question is:
how sublime-syntax files handle this kind of nidification?
Looking at the overview of the templating language over at https://cottle.readthedocs.io/en/stable/page/01-overview.html, it seems to be an easy syntax for which to write a .sublime-syntax for, but given the utter lack of resources for knowing how syntax files works in ST, I can understand it can be sometimes difficult to start or even understand.
So, I took the liberty of creating a starter syntax definition (the result of an hour & a half of boredom on a Saturday evening), which you can take and work upon. Note that I have not used the language and as such made it by just reading the docs and looking over code snippets.
You can find a gist for it here (https://gist.github.com/Ultra-Instinct-05/96fa99e1aaeb32b12d1e62109d61fcc2)
Here is a screenshot showing it in the color scheme I use (which follows the official scope naming guidelines).
It still lacks support for user defined functions (as I came to know from the docs) (and probably a few other things), but maybe that's something you can add to it !
Note that to use it, save the file as Cottle.sublime-syntax in your User package. Right now files having a .cottle extension are highlighted (because I don't know how you create a cottle file).
The syntax definition doesn't use any new feature added in ST4, so it should work the same in both ST3 & ST4.
I have different commands my program is reading in (i.e., print, count, min, max, etc.). These words can also include a number at the end of them (i.e., print3, count1, min2, max6, etc.). I'm trying to figure out a way to extract the command and the number so that I can use both in my code.
I'm struggling to figure out a way to find the last element in the string in order to extract it, in Smalltalk.
You didn't told which incarnation of Smalltalk you use, so I will explain what I would do in Pharo, that is the one I'm familiar with.
As someone that is playing with Pharo a few months at most, I can tell you the sheer amount of classes and methods available can feel overpowering at first, but the environment actually makes easy to find things. For example, when you know the exact input and output you want, but doesn't know if a method already exists somewhere, or its name, the Finder actually allow you to search by giving a example. You can open it in the world menu, as shown bellow:
By default it seeks selectors (method names) matching your input terms:
But this default is not what we need right now, so you must change the option in the upper right box to "Examples", and type in the search field a example of the input, followed by the output you want, both separated by a ".". The input example I used was the string 'max6', followed by the desired result, the number 6. Pharo then gives me a list of methods that match that:
To get what would return us the text part, you can make a new search, changing the example output from number 6 to the string 'max':
Fortunately there is several built-in methods matching the description of your problem.
There are more elegant ways, I suppose, but you can make use of the fact that String>>#asNumber only parses the part it can recognize. So you can do
'print31' reversed asNumber asString reversed asNumber
to give you 31. That only works if there actually is a number at the end.
This is one of those cases where we can presume the input data has a specific form, ie, the only numbers appear at the end of the string, and you want all those numbers. In that case it's not too hard to do, really, just:
numText := 'Kalahari78' select: [ :each | each isDigit ].
num := numText asInteger. "78"
To get the rest of the string without the digits, you can just use this:
'Kalahari78' withoutTrailingDigits. "Kalahari"6
As some of the Pharo "OGs" pointed out, you can take a look at the String class (just type CMD-Return, type in String, hit Return) and you will find an amazing number of methods for all kinds of things. Usually you can get some ideas from those. But then there are times when you really just need an answer!
I am writing documentation for a library using haddock, and, for reasons that are not really necessary to explain, I need to include a little code block in my documentation that looks like:
z(<>)
Importantly there can be no space between z and (<>). It may be a bit esoteric but
z (<>)
would make my documentation incorrect, even if it is more stylistically correct.
Now I believe that hyperlinks to both z and (<>) would be helpful. Neither has a very informative name, so a link that helps people remember their definitions and purpose is nice.
So my code without the hyperlinks looks like:
#z(<>)#
And to add hyperlinks I just use single quotes:
#'z''(<>)'#
Except that doesn't work, haddock sees 'z'' and thinks that I mean to link z' (a function that does exist in my module), and then just leaves the rest alone. The rendered output looks like
z'(<>)'
Now as an experiment I deleted the definition of z', however the only difference this makes is that the link to z' goes away. The raw text remains the same. The next thing I tried was ditching #s altogether and did
'z''(<>)'
Which also created a hyperlink to z' and left the rest untouched, the same problem as earlier except now nothing is in a code block.
How can I make a code block that links two functions without a space between?
You can separate the two functions into different code blocks. If there is no space between the code blocks, it will appear no different than a single code block. So
#'z'##'(<>)'#
will render as desired.
You can also do it in one code block by moving the 's inside of the parentheses to only surround <>.
#'z'('<>')#
This will render slightly differently with the parentheses not being part of any hyperlink, however this may be desired.
Here is an alternative solution to add to the answer you already provided:
You can mix and match ' and `. These two will also be rendered correctly by haddock:
-- | #`z`'(<>)'#
-- | #'z'`(<>)`#
At the same time I've tried your solution #'z'##'(<>)'# and for some reason it did not render for me properly, but with haddock you never know.
Here are all of the ones that I've tried:
-- * #'z'##'(<>)'#
-- * #'z'('<>')#
-- * #'z'`(<>)`#
-- * #`z`'(<>)'#
With corresponding result:
Delphi Seattle (S10). Win32 project.
Yesterday I got wrong result in my old routine.
I found this line:
sPre := Copy(aSQLText, p - 1, 1);
aSQLText was 'CREATE', and p = 1.
The sPre got "C" result.
Hmmm... Then I wrote to watch window:
Copy('ABC', 0, 1)
and the result was "A"...
Ouch... What???
The copy handles the overflow in the end well.
But not at the beginning? Or what?
I hope that I haven't got any codes which points to before the string.
Do you also got this result in your Delphi?
Why?
As I know the strings internally stored as 4 byte length + string; and they
based in 1 (not 0 as any arrays). Is this a bug?
The call to copy in your code is resolved to the internal function _UStrCopy from System.pas. Right in the beginning of its implementation it checks the Index and Count parameters and corrects them when necessary. This includes forcing the Index to point to the first character if it is too low.
I agree that this should be documented, though.
The documentation for Copy doesn't specify what will happen in this instance, so I wouldn't call it a Bug per se.
I can see arguments for both solutions (empty string or as it does, assume 1 as starting position).
Point is, as it is not defined in the documentation what happens in this instance, it is unwise for a program to assume anything one way or another, as it may be implementation dependent and might even change over the course of different versions. If your code can risk having p=1 (or even p=0) and you want the empty string in that case, you should explicitly write code to that effect instead of relying on your (wrong, in this case) expectation on what the compiler might do:
if p<=1 then sPre:='' else sPre := Copy(aSQLText, p - 1, 1);
I tried the following snippet of Alloy4, and found myself confused by the behavior of the util/Natural module. The comments explain more in detail what was unexpected. I was hoping someone could explain why this happens.
module weirdNatural
private open util/natural as nat
//Somehow, using number two obtained from incrementing one works as I expect, (ie, there is no
//number greater than it in {0,1,2}. but using number two obtained from the natrual/add function
//seems to work differently. why is that?
let twoViaAdd = nat/add[nat/One, nat/One]
let twoViaInc = nat/inc[nat/One]
pred biggerAdd {
some x: nat/Natural | nat/gt[x, twoViaAdd]
}
pred biggerInc {
some y: nat/Natural | nat/gt[y, twoViaInc]
}
//run biggerAdd for 10 but 3 Natural //does not work well, it does find a number gt2 in {0,1,2}
run biggerInc for 10 but 3 Natural //works as expected, it finds a number gt2 in {0,1,2,3}, but not in {0,1,2}
Thanks for this bug report. You are absolutely right, that is a weird behavior.
Alloy4.2 introduced some changes to how integers are handled; namely, the + and - operators in Alloy4.2 are always interpreted as set union/difference, so built-in functions plus/minus have to be used to express arithmetic addition/subtraction. On the other side, the util/natural module (mistakenly) hasn't been updated to use the latest syntax, which was the root cause of the weird behavior you experienced (specifically, the nat/add function uses the old + operator instead of plus, whereas nat/inc doesn't).
To work around this issue, you can either
open the util/natural module (choose "File -> Open Sample Models" from the main menu)
edit the file and replace the two occurrences of <a> + <b> with plus[<a>, <b>]
save the new file in the same folder with your model als file (e.g., as "my_nat.als")
open it from your main module (e.g., open my_nat as nat)
or
download the latest unofficial version where this bug is fixed (you might need to manually delete the Alloy temp folder to make sure that the Alloy Analyzer is not using the old (cached) version of the util/natural library).