The Cuis Cookbook: Difference between revisions

From Cuis CookBook
Jump to navigation Jump to search
No edit summary
m (Fix typos)
Line 2: Line 2:
A programming language cookbook is something like ''StackOverflow'', without the digging part and the try&pray experience. For a gentle and structured introduction to Cuis-Smalltalk, you should start with the '''The Cuis Book''' and '''Learning-Cuis''' more about this on the [[CuisCoookBook-References|References]]. This is intended to be a <u>resource for programmers</u>, in the sense that it answers questions that will naturally come up to programmers while exploring Smalltalk.
A programming language cookbook is something like ''StackOverflow'', without the digging part and the try&pray experience. For a gentle and structured introduction to Cuis-Smalltalk, you should start with the '''The Cuis Book''' and '''Learning-Cuis''' more about this on the [[CuisCoookBook-References|References]]. This is intended to be a <u>resource for programmers</u>, in the sense that it answers questions that will naturally come up to programmers while exploring Smalltalk.


'''Reliability'''. I am writing this notes while learning Cuis. Some of what I write may not be the best way to solve the problem, it may not even be correct. Be patient, double check! Since I use these recipes myself I am going to improve them in time.
'''Reliability'''. I am writing these notes while learning Cuis. Some of what I write may not be the best way to solve the problem, it may not even be correct. Be patient, double check! Since I use these recipes myself I am going to improve them in time.


'''Sorting principles'''. Topics order is intended to go from easy to difficult. From frequently necessary to rarely used. From needed at the beginning of the programming experience to needed by black belts. These three forces, as the 3 laws of robotics, regulate what chapter goes toward the top of the document. They hold also for sub-chapters and articles.
'''Sorting principles'''. Topic order is intended to go from easy to difficult. From frequently necessary to rarely used. From needed at the beginning of the programming experience to needed by black belts. These three forces, as the 3 laws of robotics, regulate what chapter goes toward the top of the document. They hold also for sub-chapters and articles.


'''Contributions'''. I am trying to figure out ways to make contributions possible and fruitful, see [[contributions motivated guidelines]].
'''Contributions'''. I am trying to figure out ways to make contributions possible and fruitful, see [[contributions motivated guidelines]].
Line 46: Line 46:
* [[How to use Class variables]]. STARTED
* [[How to use Class variables]]. STARTED
* [[Learn how to use the Transcript]] . This is really important, better you take a peek.
* [[Learn how to use the Transcript]] . This is really important, better you take a peek.
* [[Tips & tricks]] . Those little keyboard/mouse shortcut or little code snippet that may improve your programmer life.
* [[Tips & tricks]] . Those little keyboard/mouse shortcuts or little code snippets that may improve your programmer life.
* [[Traps and pitfalls for polyglot developers]] . If you know more programming languages this page is for you.
* [[Traps and pitfalls for polyglot developers]] . If you know more programming languages this page is for you.
* [["It didn't understand" can't happen]]. The end of most of your programmer anxiety. You can understand it all.
* [["It didn't understand" can't happen]]. The end of most of your programmer anxiety. You can understand it all.
Line 161: Line 161:


== Run external programs ==
== Run external programs ==
If you run Cuis in Linux/Unix, at to some extent also in the Mac, you can use thousands of already written shell
If you run Cuis in Linux/Unix, and to some extent also in the Mac, you can use thousands of already written shell


programs that solve the most diverse issues. Do you want to know how much free space is available on the disk?
programs that solve the most diverse issues. Do you want to know how much free space is available on the disk?


How many wireless networks your computer can see? Run a R script to make a fantastic plot? These and thousands
How many wireless networks your computer can see? Run an R script to make a fantastic plot? These and thousands


other things are possible once you are able to leverage the power of Unix from Cuis.
of other things are possible once you are able to leverage the power of Unix from Cuis.


You can perform this kind of operations with the module <code>OSProcess</code> included in Cuis or with the external package <code>CommandShell</code>. The second is easier the first is more lower level.
You can perform these kind of operations with the module <code>OSProcess</code> included in Cuis or with the external package <code>CommandShell</code>. The second is easier the first is more lower level.


* Traps and pitfalls specific to running external programs
* Traps and pitfalls specific to running external programs
* The ABC of interacting with Unix . Find this process <code>pid</code>, <code>ARGV</code>, <code>ENV</code> , <code>stdin</code>, <code>stdout</code>, <code>stderr</code> ... and all those fundamental things.
* The ABCs of interacting with Unix . Find this process <code>pid</code>, <code>ARGV</code>, <code>ENV</code> , <code>stdin</code>, <code>stdout</code>, <code>stderr</code> ... and all those fundamental things.
* Run a program with OSProcess
* Run a program with OSProcess
* Run a program with CommandShell
* Run a program with CommandShell
Line 180: Line 180:
* How to ping a computer
* How to ping a computer
* How to discover the IP of a given host name
* How to discover the IP of a given host name
* How to get a webpage content
* How to get a webpage's content


== Databases ==
== Databases ==
Line 191: Line 191:
This section is about setting Cuis to start up in the way you like it, on any image you may want to boot.
This section is about setting Cuis to start up in the way you like it, on any image you may want to boot.


* Author name and initial programmatically
* Author name and initials programmatically
* Set your preferred font size
* Set your preferred font size
* Set your user name
* Set your user name
* Stop the system from asking to save the image on pressing Cuis World->Quit
* Stop the system from asking to save the image on pressing Cuis World->Quit
* An example of customized Cuis startup Requires only one executable script file !
* An example of customized Cuis startup Requires only one executable script file !
* Do ENV variables affects cuis ?
* Do ENV variables affect Cuis ?
* How do I pass a string to be executed by Cuis when it boots ?
* How do I pass a string to be executed by Cuis when it boots ?
* How do I pass a file to be executed by Cuis when it boots ?
* How do I pass a file to be executed by Cuis when it boots ?
* How to quit Cuis immediately. No question asked.
* How to quit Cuis immediately. No questions asked.


== Scripting with Cuis ==
== Scripting with Cuis ==
Is it possible to make Unix scripts with Cuis? Does it make any sense? This section explores these subject.
Is it possible to make Unix scripts with Cuis? Does it make any sense? This section explores these subjects.


* Initial considerations. here
* Initial considerations. here


= Delivering an application written in Cuis =
= Delivering an application written in Cuis =
This sections explores ways in which you can have other people, non programmers, use the your coolest applications. To run the application it may be necessary to: [1] Run VM and an Image [2] Run VM + Image + some code snippet passed as a String [3] Run VM + Image + a script file.
This section explores ways in which you can have other people, non programmers, use your coolest applications. To run the application it may be necessary to: [1] Run VM and an Image [2] Run VM + Image + some code snippet passed as a String [3] Run VM + Image + a script file.


* Deploy a Cuis application in Linux
* Deploy a Cuis application in Linux
Line 216: Line 216:


* Basic operations with Morphs
* Basic operations with Morphs
* Kill a Morph . A few ways to do destroy a Morph.
* Kill a Morph . A few ways to destroy a Morph.
* Place Morphs in World as you wish, automatically
* Place Morphs in World as you wish, automatically
* Drawing and pictures with the ImageMorph
* Drawing and pictures with the ImageMorph
Line 223: Line 223:
* How to layout the Morphs . This is the basic step to know prodromic to make your own GUI in Cuis.
* How to layout the Morphs . This is the basic step to know prodromic to make your own GUI in Cuis.
* Fonts - 1. First interactions with Fonts
* Fonts - 1. First interactions with Fonts
* Basic events handling in Morphic . Here we see how to do something when a mouse button or a key on the keyboard get pressed.
* Basic event handling in Morphic . Here we see how to do something when a mouse button or a key on the keyboard get pressed.


= The Sound system =
= The Sound system =
To some people doing programming is manipulating sounds. As for some other people it is building nice graphical user interface or some one else does networks services. For this reason the sound system chapter is placed after Morphic.
To some people doing programming is manipulating sounds. As for some other people it is building a nice graphical user interface or some one else does networks services. For this reason the sound system chapter is placed after Morphic.
* [[First experiments with sound]] . Collecting knowledge here, when ready will be splitted in topics
* [[First experiments with sound]] . Collecting knowledge here, when ready will be split into topics


= Introspection and The compiler =
= Introspection and The compiler =
This notes are taken reading the wonderful document "The HitcHiker's guide to the Smalltalk Compiler" by Vassili Bykov, here .
These notes are taken reading the wonderful document "The HitchHiker's guide to the Smalltalk Compiler" by Vassili Bykov, here .


* get the current World object.
* get the current World object.
Line 242: Line 242:


* Building the Virtual Machine
* Building the Virtual Machine
* Building the VectorGraphcis plugin
* Building the VectorGraphics plugin
* Choosing between FFI and plugin
* Choosing between FFI and plugin
* Run a script with a proper window title
* Run a script with a proper window title

Revision as of 03:07, 12 May 2025

A programming language cookbook is something like StackOverflow, without the digging part and the try&pray experience. For a gentle and structured introduction to Cuis-Smalltalk, you should start with the The Cuis Book and Learning-Cuis more about this on the References. This is intended to be a resource for programmers, in the sense that it answers questions that will naturally come up to programmers while exploring Smalltalk.

Reliability. I am writing these notes while learning Cuis. Some of what I write may not be the best way to solve the problem, it may not even be correct. Be patient, double check! Since I use these recipes myself I am going to improve them in time.

Sorting principles. Topic order is intended to go from easy to difficult. From frequently necessary to rarely used. From needed at the beginning of the programming experience to needed by black belts. These three forces, as the 3 laws of robotics, regulate what chapter goes toward the top of the document. They hold also for sub-chapters and articles.

Contributions. I am trying to figure out ways to make contributions possible and fruitful, see contributions motivated guidelines.

Copyright. You have the right to read, print for your own use and contribute to the document. You can make external links to this document. You can not copy the document and make it available somewhere else on the Internet. You can't claim ownership. You can't bring the document to an editor and publish it. I, as the author of more than 99% of the words here displayed retain all rights as well as the right to change these rules.

  • Introduction. What you should expect from this book and the reason why I am writing it. STARTED.
  • Why Smalltalk?. For what reason should you learn another programming language which is also not so popular. Read on, there are very good reasons. STARTED.

Installation and start up

Cuis in its environment

Things unique to Cuis and/or Smalltalk

Here are all the things that are totally unknown for anybody who never programmed in any Smalltalk.

About a general Class and Object

Data Structures

  • Fundamentals: numbers, strings and symbols

Strings (before default UTF)

Collections

Streams

Date and time

Files and directories

You should keep in mind that Smalltalk uses files but it is not based on files. I copy here

part of a Juan mail to mailing list: "... The essential idea you need to be aware of when learning about all this is that Smalltalk uses files, but it is not file-based. What this means is that all the tools in the Smalltalk image (with the only exception of FileList and FileContentsBrowser) are NOT showing files, but live objects. The way them relate to files is usually not really important ...".

Error Handling and the Debugger

Processes

Uncategorized useful features

Run external programs

If you run Cuis in Linux/Unix, and to some extent also in the Mac, you can use thousands of already written shell

programs that solve the most diverse issues. Do you want to know how much free space is available on the disk?

How many wireless networks your computer can see? Run an R script to make a fantastic plot? These and thousands

of other things are possible once you are able to leverage the power of Unix from Cuis.

You can perform these kind of operations with the module OSProcess included in Cuis or with the external package CommandShell. The second is easier the first is more lower level.

  • Traps and pitfalls specific to running external programs
  • The ABCs of interacting with Unix . Find this process pid, ARGV, ENV , stdin, stdout, stderr ... and all those fundamental things.
  • Run a program with OSProcess
  • Run a program with CommandShell

Networking and the Web

  • How to ping a computer
  • How to discover the IP of a given host name
  • How to get a webpage's content

Databases

  • Talk to PostgreSQL. See the PostgreSQL package, it has documentation.
  • Talk to MongoDB
  • Talk to SQlite

Scripting Cuis

This section is about setting Cuis to start up in the way you like it, on any image you may want to boot.

  • Author name and initials programmatically
  • Set your preferred font size
  • Set your user name
  • Stop the system from asking to save the image on pressing Cuis World->Quit
  • An example of customized Cuis startup Requires only one executable script file !
  • Do ENV variables affect Cuis ?
  • How do I pass a string to be executed by Cuis when it boots ?
  • How do I pass a file to be executed by Cuis when it boots ?
  • How to quit Cuis immediately. No questions asked.

Scripting with Cuis

Is it possible to make Unix scripts with Cuis? Does it make any sense? This section explores these subjects.

  • Initial considerations. here

Delivering an application written in Cuis

This section explores ways in which you can have other people, non programmers, use your coolest applications. To run the application it may be necessary to: [1] Run VM and an Image [2] Run VM + Image + some code snippet passed as a String [3] Run VM + Image + a script file.

  • Deploy a Cuis application in Linux
  • Deploy a Cuis application in Windows-10
  • Deploy a Cuis application in MacOS

Morphic Cookbook

  • Basic operations with Morphs
  • Kill a Morph . A few ways to destroy a Morph.
  • Place Morphs in World as you wish, automatically
  • Drawing and pictures with the ImageMorph
  • Application. Convert a color image to black and white
  • Application. Show contours in an image
  • How to layout the Morphs . This is the basic step to know prodromic to make your own GUI in Cuis.
  • Fonts - 1. First interactions with Fonts
  • Basic event handling in Morphic . Here we see how to do something when a mouse button or a key on the keyboard get pressed.

The Sound system

To some people doing programming is manipulating sounds. As for some other people it is building a nice graphical user interface or some one else does networks services. For this reason the sound system chapter is placed after Morphic.

Introspection and The compiler

These notes are taken reading the wonderful document "The HitchHiker's guide to the Smalltalk Compiler" by Vassili Bykov, here .

  • get the current World object.
  • what happens when Cuis start up.
  • the main loop.
  • The Cuis scanner.
  • The Cuis parser.
  • See the compiled code.

The Virtual Machine

  • Building the Virtual Machine
  • Building the VectorGraphics plugin
  • Choosing between FFI and plugin
  • Run a script with a proper window title

Applications built on Cuis

  • DrGeo

TODO

These are reminders for me about things to do in the Cookbook or in Cuis

  • DEV. SpellChecker, for text panes in Cuis. It would be useful to be able to spellcheck comments in code. I like to put comments, without spell checker they are so full of bugs they appear really untrustworthy.
  • Video about class variables.
  • Page about ';' -- '::' -- 'yourself'.
  • Video about installation of Cuis, not so easy the first time
  • Video about updating Cuis, not obvious
  • Video about using the Transcript efficiently
  • Video about creation of a minimal GUI
  • Video about creation of a minimal application, runnable from Linux command line
  • Video about creation of a minimal application, runnable from Windows GUI
  • Video about making Tests, and discovering how to use existing classes with them
  • Video-or-page about variables, especially class variables