Skip to content
Tim Burks edited this page Jul 28, 2019 · 2 revisions

Goals

Useful existing features of Nu:

  • S-expression grammar.
  • Macros and special-purpose operators (e.g. Markup generation)
  • Built-in code formatting.
  • Easy integration with C code using an Objective-C runtime.

Interesting new features:

  • Explicit support for Protocol Buffer serialization and deserialization.
  • Protocol Buffer representation of parsed code and program state.
  • Packages for high-level code organization.
  • Data structures represented as messages. Composition used instead of inheritance.
  • Methods as functions bound to messages.
  • Dot notation for concise access to package and message members.
  • Keyword arguments for functions and methods.
  • Freezable state for transporting running programs between servers.

Operators

Code structure

operator description
package Declare a package. A package can contain messages, services, and functions.
message Declare a message. A message is a collection of fields and optional functions.
service Declare a service. A service is a collection of rpcs.
rpc Declare a remote procedure call.
func Define a function. Functions can be anonymous or named and optionally associated with messages.
set Create a variable and set it or modify an existing variable.
car cdr cons Every Lisp needs these basic list manipulation operators.

Built-in types

All of these (except character and error) can be used in a message declaration to declare a field. All can be used as operators to “cast” a value to the associated type or return nil if the value is not representable with that type.

operator description
map Associative map.
array Array (repeated field).
error Get an error from a value or return nil if there is no error.
double float Floating-point types
int32 int64 uint32 uint64 sint32 sint64 fixed32 fixed64 sfixed32 sfixed64 Integer types
bool Boolean
string A string must always contain UTF-8 encoded or 7-bit ASCII text.
bytes May contain any arbitrary sequence of bytes.
character UTF-8 code point. May not be used in messages (use int32 instead).
enum 32-bit integer
oneof Groups fields so that at most one can be set.

Concurrency

operator description
go Start a concurrent process
condition.new Create a condition variable

Control flow

operator description
if then else
cond else
while

Evaluation

operator description
quote Quote an expression.
eval Evaluate an expression.
defer Evaluate an expression at the end of the current block, implicitly quoting the expression.

Arithmetic

operator description
+ - * /
eq ne

Input/Output

operator description
puts
reads
putf
readf

Protocol Buffer integration

Messages can be declared with expressions, stored to variables, and used to call protoc plugins.

File descriptor sets can be read and parsed into package descriptions, and then displayed as expressions.