Programming in 5D

Gentle Introduction

For a gentle introduction, see 5D Tutorial.

Source Code Character Set

The Source Code Character Set is supposed to be UTF-8.

The first 128 characters are used for the following:

CodeUsage
NULHas no meaning
SOH, STX, ETX, EOTHave no meaning
ENQ, ACK, BEL, BSHave no meaning
TABSignificant Whitespace
LFNewline, used for indentation tracking
VTHas no meaning
FFHas no meaning
CRIgnored (!!!)
SO, SI, DLE, DC1Have no meaning
DC2, DC3, DC4Have no meaning
NAK, SYN, ETBHave no meaning
CAN, EM, SUBHave no meaning
ESCHas no meaning
FS, GS, RS, USHave no meaning
spaceSignificant Whitespace
!Part of identifiers
"Marks literal Str
#Special literal values
$Operator
%Operator
&Operator
'Marks quoted expression
(Grouping
)Grouping
*Operator
+Operator
,Operator
-Operator
.Operator or part of a floating-point number
/Operator
0..9Part of numbers or (identifiers starting from the second place)
:Operator
;Operator
<Operator
=Operator
>Operator
?Part of identifiers
@Keywords
A..ZPart of identifiers
[List macro
\Abstraction
]List macro
^Operator
_Operator
`Operator ?
a..zPart of identifiers
{Literal Sets, Dictionaries
|Operator
}Literal Sets, Dictionaries
~Operator
DELHas no meaning

Valid Names

frobnicate
μ
mayTheForceBeWithYou42
σ
ελεκτρων
+
**
⋅

Valid Numbers

5
(-3)
5.23232245322151
358888888888888888888888888888888888888888888888888888888888888888888888888888
#xFF                    => 255
#o777                   => 511
#\A                     => 65   -- the character code of A

Module System

In order to access modules, use the requireModule function.

Note that this automatically ensures that the module isn't loaded twice.

Result is the module. By convention, you can check for exports by using the expression:

(requireModule "IO").exports

Foreign Function Interface

You can load and call procedures of shared libraries:

Example:

let FFI := requireModule "FFI" in 
let requireSharedLibrary := FFI.requireSharedLibrary in 
let puts! := FFI.requireSharedLibrary "/lib/x86_64-linux-gnu/libc.so.6" 'Cip "puts" in 
puts! "Hello world"

What this does is:

- load the library with the given file name.

- give a procedure signature (usually as a Symbol).

- give the name of the procedure to load (usually as a Str).

- result is a callable.

The procedure signature is a Symbol whose str consists of the following characters:

  • The calling convention, C.
  • The type of the return value.
  • The type of each of the parameters of the C procedure, in order.
  • Result is a function which can be run in a World.

    Possible type specifiers:

    LetterMeaning
    SString or nil
    sString
    P(non-String) pointer or nil
    p(non-String) pointer
    iint or smaller
    llong
    vvoid
    Llong long
    ffloat
    ddouble