Menu

Defining a function

Mark Anthony Taylor (Shyreman)

Use (function ...) to declare a function.

Functions take inputs and maps them to outputs using a body of logic. This is specified thus:

(function (<input_type1> <input_name1>) .... (<input_typeN> <input_nameN>)
                                ->
          (<output_type1> <output_name1>) .... (<output_typeN> <output_nameN>)
                                :
                                <body>
)

A function that specifies no input and maps to a single output value is called a get-accessor

Example:

(function PI -> (Float64 valueOfPi):
    (valueOfPi = 3.14159)
)

Currently a function definition that specifies no output still requires a mapping symbol (->), and the
programmer should be sure to use blank space to separate this from the body indicator symbol (:).

Example:

(function RingBell (Float64 hz)(Float64 decibels)-> :
    (Sys.Native.Audio.Beep hz decibels)
)

Related

Wiki: Content

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.