Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Symta v0.2

Name: Anonymous 2012-12-08 11:36

Ok. I put out the second release of Symta: http://sym.at.ua/load

Also the SymCraft/LispCraft sources are under 1100 lines (http://sym.at.ua/photo), including UI and a simple AI.

Name: Anonymous 2012-12-11 17:43

>>89
I'll try to rewrite Arc tutorial for this purpose...


[This is a brief tutorial on Symta.  It's intended for readers with
some Lisp experience.]


Symta programs consist of expressions.  The simplest expressions are
things like numbers and strings, which evaluate to themselves.

-> 25
25
-> “foo”
“foo”
-> ~123  // negative number
~123

Note the unicode “” (U+201C and U+201D) quotes, which can be easily
nested. For convenience we also support usual "" ASCII-quotes.

Several expressions enclosed within parentheses are also an expression.
These are called lists.  When a list is evaluated, the elements are
evaluated from left to right, and the value of the first (presumably
a function) is passed the values of the rest.  Whatever it returns
is returned as the value of the expression.

-> `+` 1 2
3

Here's what just happened.  First `+`, 1, and 2 were evaluated,
returning the plus function, 1, and 2 respectively.  1 and 2 were
then passed to the plus function, which returned 3, which was
returned as the value of the whole expression.  `` quotes allow
us to use any string (even ()-braces) as a function/variable name.

(Macros introduce a twist, because they transform lists before
they're evaluated.  We'll get to them later.)

Since expression and evaluation are both defined recursively,
programs can be as complex as you want:

-> `+` (`+` 1 2) (`+` 3 (`+` 4 5))
15

Putting the `+` before the numbers looks odd when you're used to
writing "1 + 2," but Symta, in contrast to other Lisps, supports
infix sugar, which automatically transforms expressions into
their prefix form:

-> 1+2+3+4+5
15

This turns out to be a convenient feature, and doesn't impede
generating code that much, which is a common thing to do in Lisp.

Also, in contrast to other Lisp dialects, Symta doesn't discern
between strings and symbols. We've already seen one: `+` which is
just an unquoted “+” string, being treated as code. Unquoted strings
don't evaluate to themselves the way numbers and “”-strings do.
They return whatever value they've been assigned.

If we give Foo the value 13, it will return 13 when evaluated:

-> Foo = 13
13
-> Foo
13

Note that all variables must start from uppercase letter, which
functions can start from any non-uppercase character. Such
notation improves readability and frees non-uppercase symbols
for special use.

You can turn off evaluation by putting the \ slash character
before an expression.  So \Foo returns the symbol Foo.

-> \Foo
Foo


If you quote a list, you get back the list itself. 

-> (`+` 1 2)
3
-> \(`+` 1 2)
(`+` 1 2)

-> `\\` 1+2   // note how we escape \ slash to use it inside string
(`+` 1 2)

The first expression returns the number 3.  The second, because it
was quoted, returns a list consisting of the symbol + and the numbers
1 and 2. The third expression show how to escape infix expressions.

You can build up lists with [] and @
-> [1 2]
(1 2)

-> [\f @\(a b)]
(f a b)

-> [1 @[2 3] 4 @[5 6] 7]
(1 2 3 4 5 6 7)

-> l 1 @[2 3] 4 @[5 6] 7
(1 2 3 4 5 6 7)

-> `[]` (1 @[2 3] 4 @[5 6] 7)
(1 2 3 4 5 6 7)

As you can see operator `@` does an interpolation inside `[]`,
while `l` is used when you want to avoid braces. Last line shows
that `[]` is in fact a "macro", which doesn't eval it's arguments,
but transforms them into a number of calls to low-level `conc`,
`pre`, `suf` and functions (similar to CONS from Common Lisp),
which would be too error prone to use directly.


While by default interpolating operator `@` doesn't change the
original list, with `!` it can be made easily used to do so:

-> Yoba = \(a b)
(a b)
-> [\f @Yoba]
(f a b)
-> Yoba
(a b)

-> [\f @!Yoba]
(f a b)
-> Yoba
(f a b)

In general, any variable prefixed by `!` takes value of resulting
expression. If you are used to C/C++, you can easily simulate `++`
and `--`, with `!`:

-> Yoba = 123
123
-> !Yoba+1
124
-> Yoba
124
-> !!Yoba+1
124
-> Yoba
125

While `!!` too sets Yoba to the new value, it returns previous one,
acting like postfix `++` from C/C++.


The empty list is represented by the symbol ø, which is defined
to evaluate to itself. For the same purpose we can use just ()

You can take lists apart with lhd, ltl, rhd and ltl functions, which
return the head element and tailing elements relatively to the beginning
and to the end of a list respectively:

-> lhd \(a b c)
a
-> ltl \(a b c)
(b c)
-> rhd \(a b c)
c
-> rtl \(a b c)
(a b)

Another operator `,` picks element by it's numeric position in list:
-> [1 2 3],0
1
-> [1 2 3],(~1) // when index is negative, takes from the end
3

function `t` and `d` take and drop number of elements from a list:
-> t 3 [1 2 3 4 5 6 7]
(1 2 3)
-> t ~3 [1 2 3 4 5 6 7]
(5 6 7)
-> d 3 [1 2 3 4 5 6 7]
(4 5 6 7)
-> d ~3 [1 2 3 4 5 6 7]
(1 2 3 4)

Generic Symta lists must guarantee reasonably fast O(log2(N)) random
access and concatenation. This may not apply to lists, optimized for
specific purpose like arrays or hash-tables.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List