The Cuis Cookbook

From Cuis CookBook
Revision as of 23:33, 3 May 2025 by Nmingott (talk | contribs) (added links)
Jump to navigation Jump to search

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.

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.

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.

Contribution. If you wish to contribute send me a pull request.

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

  • The things you may call a List -- STARTED
  • Array
  • Dictionary a.k.a. Hash Table

Streams

  • Make a stream from a string, for reading.
  • Write a long String with a Stream
  • Write to stdout in any system. Not only Unix like. Useful for shell programs.

Date and time

  • Get the current date and time
  • Format date and time as you like most
  • Date and time algebra
  • Get the current time with the highest precision
  • Get date and time as Unix epoch
  • Get date and time in a different country
  • Measure how much time it takes to run a code block

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 ...".

  • How to Read or Write a text file . without Streams, only Strings.
  • How to Read or Write a text file with a Stream
  • Read a file line by line . Or any general delimiter.
  • Find the current directory, list it and move in the directory tree
  • Filename extensions: .txt, .csv, .json ...
  • Check things on a pathname. Is there anything? Is it a file? Is it writable? ...
  • Delete files and directories
  • Read/Write a binary file
  • Create a new non-existing file name
  • Using file locks -- TODO
  • Get the list of open files
  • Get the directory where a Class (its Package) is stored
  • Where is the image file? Where is the VM?

Error Handling and the Debugger

  • Call the debugger from a code location
  • Quick exception handling, equivalent of Python try ... except
  • Assertions
  • Errors, raise and catch signals
  • Case-study-1. TODO. When the debugger pops up send me an email
  • b

Processes

  • Smalltalk processes are not Unix processes
  • See the list of running processes
  • Processes 101. Shows how to create a process, name it, start it, stop it and destroy it.
  • Run a new process
  • Kill a process

Uncategorized useful features

  • Run a method every 2 hours or every day at 15:00, equivalent to Unix cron
  • Zip and unZip files and directories --- TODO, miss zipping
  • Convert a file to/from Base64
  • Deal with XML files -- STARTED
  • About Random
  • How to invoke the garbage collector
  • Adapt newline characters to Cuis standard
  • Where to get information about the hardware . Screen size, free memory, cpu speed ...
  • The Dependency Mechanism - part 1. Here we talk about the Smalltalk classic Parent - Dependent model.
  • The Dependency Mechanism - part 2. Here we explain the why of a Model class.
  • The Dependency Mechanism - part 3. Here we talk about the Observer Pattern. (preferred current method in Cuis)
  • How to use the serial port. See SerialPort package, it has documentation.

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

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

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 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 ABC 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 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 initial 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 affects 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 question asked.

Scripting with Cuis

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

  • Initial considerations. here

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.

  • 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 do 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 events handling in Morphic . Here we see how to do something when a mouse button or a key on the keyboard get pressed.

Introspection and The compiler

This notes are taken reading the wonderful document "The HitcHiker'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 VectorGraphcis 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