Skip to content

Instantly share code, notes, and snippets.

@johnwcowan
Last active August 29, 2022 16:34
Show Gist options
  • Save johnwcowan/cbf703f2d61d265e8f1e92fdbc0cb5ce to your computer and use it in GitHub Desktop.
Save johnwcowan/cbf703f2d61d265e8f1e92fdbc0cb5ce to your computer and use it in GitHub Desktop.
AVSL (A Very {Simple|Small|Safe} Language) in a nutshell
Goals:
Easy to learn and use by beginning programmers
Easy to relearn and use by "perpetual intermediate" programmers
Suitable for use as a front-end language (not in a browser)
Not infuriating to advanced programmers modulo syntax
Support a "professional" syntax
Case insensitive (except strings)
Everything should be as simple as possible but no simpler
High-level design choices:
Mostly intended for easy UI programming
Supports both GUI/TUI and CLI users, probably with different clients
Simple imperative language (neither OO nor FP)
Dynamically typed
Numbers are not exact or inexact, operators are
Python-style indentation
Influences:
ABC (the ancestor of Python)
PROMAL (language for Apple II and Commodore C64)
JSON
Types:
Numbers (immutable)
Dates (immutable) TBD
Texts (immutable)
Truth values (immutable)
Null (immutable)
Lists (mutable)
Dictionaries (mutable)
Simple lexical syntax:
Single-line commands
Case insensitive
Variables and keywords: start with a Unicode letter, then Unicode letters and digits
Number formats: 123, 3/4 123.45, 0.1, 1.0, 3.2e10, 3.2e-10, 0.nan, 0.inf
Date format: 2020-12-27T20:02:05+07:00 (or -07:00)
Text (string) formats: "this", 'that', "nested ""quotes"" doubled", """quotes
with newlines""" (because line-oriented language)
Truth values: true, false
Null value: null
Dates: ISO 8601
Compound lexical syntax:
Lists: [exp, ...) or []
Sets: {expr,...} ; notation for empty set is SET()
Dictionaries: {entry:value, ...} or {}
Subscripting: [expr] for selection, [expr:expr] for slicing lists or strings; return copies
also allowed where vars are
Commands for collections:
ADD expr TO expr ; for sets
ADD KEY expr VALUE expr TO expr ; for dictionaries
ADD expr TO expr AT expr ; for lists
REMOVE expr FROM expr ; for sets and dictionaries
REMOVE exper TO expr FROM expr ; for lists
Block commands:
IF expr: ; No else clause
SELECT: expr1 ; Execute block on first expr2 = expr1
expr2: ; Default expr1 is true
...
LOOP WHILE expr: ; Execute block while expr is true
LOOP var IN expr: ; Loop over collections
LOOP var FROM expr TO expr: ; Loop over numeric range (inclusive)
TRY: ; TBD
Input commands:
TIE INPUT type -> var ; Request input of the specified type
; to be put in var (now in CLI, linkage set up in GUI)
TIE CHOICE set-expr -> var ; Similar, but user picks one element of the set
TIE CHOICES set-expr -> var ; Similar, but user picks one or more elements of the set
WAIT text-expr ; Display text-expr to user (possibly as a button)
; and suspend execution until the user responds
; Note: tied variables are frozen after this
WAIT IMAGE url-expr ; Same idea, but image is fetched from URL
HTTP commands:
GET url-expr -> var STATUS var
PUT expr -> url-expr STATUS var
POST|PATCH expr TO url-expr -> var STATUS var
REMOVE url-expr STATUS var
Results become an image, a list of strings, or an arbitrary object when JSON, or ???
Assignment and binding:
PUT expr -> var ; Assign to mutable variable
LET var BE expr ; Bind variables to immutable variable
LET var, ... BE expr, ... ; Bind variables to immutable variables from series
Miscellaneous commands:
DO NOTHING
SHARE var, ... ; Declare a global variable (globally or locally)
CHECK bool-expr ; Program aborts if expr is false
SHOW expr, ... ; Output values of expressions
SHOW expr, ... , ; Final comma suppresses newline
SHOW LINK url TEXT string ; Display a link
DEBUG PRINT expr, ... ; Sent to the console window
SHOW IMAGE url-expr ; Fetch image from URL and show it
SET RANDOM ; Randomize the random number sequence
DONE ; Terminate defined command or program
RETURN expr ; Return value from an operator
Definitions:
HOW TO keywords <var ...> ... ; Multiple keywords allowed
[ -> <var> ...] ; Variable names are in explicit angle brackets
OPERATION <var> keywords <var> ; Define a dyadic operation
OPERATION keywords <var> ; Define a monadic operator
Arithmetic operators:
+, -, *, / ; Exact but sometimes slow
.+, .-, .*, ./ ; Fast but inexact
ROOT expr ; square root
expr1 ROOT expr2 ; expr1-th root
- expr ; negation
Other numeric operators:
ABS expr
SIGN expr
FLOOR expr, CEILING expr, ROUND expr
expr1 MOD expr2
NUMERATOR expr, DENOMINATOR expr
RANDOM, RANDOM expr ; random number from 0 to 1, random integer from 0 to expr
MIN expr, MAX expr ; minimum or maximum of list of numbers
TBD: trig, exp, log
Text operators:
LOWER expr, UPPER expr
STRIP expr
expr1 JOIN expr2 ; join list of texts in expr2 using expr1
expr1 SPLIT expr2 ; split list of texts in expr2 using expr1 delimiter
Truth value operators:
AND, OR, NOT
Date operators:
TBD
Set operators
SET () ; return empty set
Conversion operators:
Applying LIST to a list or DICTIONARY to a dictionary makes a copy.
NUMBER expr ; converts text to number
TEXT expr ; uses lexical-syntax representations of all other types
DATE expr ; string to date, number??
LIST expr ; converts text, dictionary
; dictionary becomes list of 2-element lists
DICTIONARY expr ; converts list of 2-element lists
Generic operators:
expr1 ++ expr2 ; concatenate texts, lists, sets, dictionaries
; text can be concatenated with anything (?)
LENGTH expr ; length of texts, lists, sets, dictionaries, series
<, =, >, <=, >=, != ; compare texts, sets, numbers
IN, NOT IN ; inclusion in texts, lists, sets, dictionaries
CHOICE OF expr ; choose random item from list, set
SQLite support?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment