Fn2

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Intro

Another language I am thinking about.

Premise

  • Like Python, variables aren't typed but values are.
  • Simple syntax.
  • No operators.
  • Objects don't have methods. Methods are functions that know how to work with each object because that behavior is described by the object.
  • Functions don't have to evaluate the args before doing their work. They can process the args before they are evaluated for some fancy-schmancy stuff.
  • The actual language is quite small. All the neat stuff is added on top to make it more usable.

Syntax

  • Literals
1.0     # Float 1.0
3       # Integer 3
"asdf"  # String "asdf"

  • variable lookup
foo
  • Calling functions/macros
foo(a b c) # Note: Not all functions evaluate each argument. These are called "macros".
  • Variable assignment
set(a 5) # Note: 'a' is not evaluated, although it is inspected.

Evaluation

The top-level symbol is evaluated.

Lookup

foo

This means, "Lookup the value of the variable named 'foo'". The order of looking something up is:

  1. Built-in. If 'foo' is defined as a built-in, then call that.
  2. Lexical. If 'foo' was defined locally, use that. If it was defined in the context that this code block was defined, then use that.
  3. Dynamic. Look at the calling context for the dynamic variable of the same name.

Function Call

foo(a b c)

This means, "call the value of foo with parameters 'a', 'b', and 'c'." Note that 'a', 'b', and 'c' are not necessarily evaluated as part of the call, merging the concepts of macros and functions together.

Item Lookup

foo[a]

This means, "Evaluate 'a'. Lookup item 'a' in 'foo'."

Attribute Lookup

foo.a

This means, "Evaluate 'foo'. Lookup 'a' in the value."

Built-Ins

The basic data types are:

  • bits
  • integers
    • int8
    • int16
    • int32
    • int64
    • int<n>
    • bigint
  • floats
    • float16
    • float32
    • float64
  • decimals
  • rationals
  • char (unicode char)
  • vector
  • dict

More later...