Wren

Wren, un linguaggio di scripting piccolo e veloce, a classi: prompt interattivo e script, con un piccolo modulo io (Stdin, File). Scrivi wren per il prompt, wren script.wren per eseguire un file.

versione 0.4.0 · Licenza: MIT · Sito del progetto

Wren

A cosa serve

Wren è un linguaggio di scripting piccolo, veloce e ordinato, a classi (un po' Smalltalk, un po' Lua, con una sintassi alla C). Ha fiber, closure, liste, mappe e range. Qui hai il prompt interattivo e l'esecuzione di file .wren.

Come si usa

Comando Cosa fa
wren apre il prompt interattivo (>)
wren script.wren esegue un file dalla cartella home
wren script.wren a b passa argomenti, letti con Process.arguments
wren -e 'System.print(6 * 7)' esegue una riga al volo

Nel prompt un'espressione mostra il suo valore; se lasci aperta una parentesi (, [ o { la riga continua con ...:

> 1 + 2 * 3
7
> var lista = [1, 2, 3, 4]
> lista.map {|n| n * n }.toList
[1, 4, 9, 16]
> System.print("due più due fa %(2 + 2)")
due più due fa 4
> class Cane {
...   construct new(nome) { _nome = nome }
...   abbaia() { "%(_nome): bau!" }
... }
> Cane.new("Fido").abbaia()
Fido: bau!

Il modulo io legge e scrive file e legge l'input:

import "io" for File, Stdin
File.write("/nota.txt", "ciao da Wren")
System.print(File.read("/nota.txt"))
var riga = Stdin.readLine()

Negli script import "nome" carica nome.wren dalla stessa cartella. Ci sono anche i moduli random e meta. Per uscire: EOF.

Limiti

Questa non è la wren_cli ufficiale (che richiede libuv): mancano timer, rete, processi e il modulo os. Del modulo io ci sono solo File.read, File.write, File.exists, Stdin.readLine e Process.arguments. Memoria disponibile: fino a 8 MB.

Nel Terminale

Wren

Wren, a small, fast class-based scripting language: interactive prompt and scripts, with a mini io module (Stdin, File). Type wren for the prompt, wren script.wren to run a file.

version 0.4.0 · License: MIT · Project site

Wren

What it is

Wren is a small, fast, tidy class-based scripting language (a bit Smalltalk, a bit Lua, with a C-like syntax). It has fibers, closures, lists, maps and ranges. You get the interactive prompt and .wren file execution.

How to use it

Command What it does
wren opens the interactive prompt (>)
wren script.wren runs a file from the home folder
wren script.wren a b passes arguments, read with Process.arguments
wren -e 'System.print(6 * 7)' runs one line

At the prompt an expression shows its value; leave a (, [ or { open and the input continues with ...:

> 1 + 2 * 3
7
> var list = [1, 2, 3, 4]
> list.map {|n| n * n }.toList
[1, 4, 9, 16]
> System.print("two plus two is %(2 + 2)")
two plus two is 4
> class Dog {
...   construct new(name) { _name = name }
...   bark() { "%(_name): woof!" }
... }
> Dog.new("Rex").bark()
Rex: woof!

The io module reads and writes files and reads input:

import "io" for File, Stdin
File.write("/note.txt", "hello from Wren")
System.print(File.read("/note.txt"))
var line = Stdin.readLine()

In scripts import "name" loads name.wren from the same folder. The random and meta modules are there too. To quit: EOF.

Limits

This is not the official wren_cli (which needs libuv): no timers, network, processes or os module. Of the io module there are only File.read, File.write, File.exists, Stdin.readLine and Process.arguments. Memory: up to 8 MB.

In the Terminal