Compare commits

..

No commits in common. "master" and "live-readme-repl" have entirely different histories.

5 changed files with 12 additions and 16 deletions

View File

@ -1,4 +1,4 @@
# ![PebbLisp](https://git.sagev.space/sage/pebblisp/raw/branch/master/resources/images/pebblisp-logo-white.png) # PebbLisp
A very basic LISP implementation with an interpreter and editor written for the Pebble. A very basic LISP implementation with an interpreter and editor written for the Pebble.
@ -90,14 +90,15 @@ write:
Calling it is as simple as `(sq 5)`, which returns `25`. Calling it is as simple as `(sq 5)`, which returns `25`.
Lambdas can also be applied anonymously. This is most useful when using something like `map`. For example, an anonymous lambda could be used to square each Lambdas can also be applied anonymously, as in `((fn (a) (* a a)) 5)`, which also returns `25`.
This is most useful when using something like `map`. For example, an anonymous lambda could be used to square each
element in a list: element in a list:
``` ```
(map (fn (a) (* a a)) (1 2 3 5 8 13 21 34)) (map (fn (a) (* a a)) (1 2 3 5 8 13 21 34))
``` ```
This is particularly valuable on a low-memory device like the Pebble, where it may be wise to avoid storing the named This is particularly useful on a low-memory device like the Pebble, where it may be useful to avoid storing the named
lambda object in the environment. lambda object in the environment.
Lambdas may also have no arguments: Lambdas may also have no arguments:
@ -146,19 +147,19 @@ input list.
## Fil ## Fil
`fil` returns a filtered list, based on a given list and a given condition. The general form of a `fil` `fil` returns a filtered list, based on a given list and a given condition. Partial function support in PebbLisp is
nowhere near comprehensive, but `fil` operates on the bare notion that currently exists. The general form of a `fil`
expression is expression is
``` ```
(fil (condition) (candidate-list)) (fil (partial-condition) (candidate-list))
``` ```
Each element in the candidate list is compared against the Each element in the candidate list is compared against the partial condition. If the comparison returns true, it is
condition. If the comparison returns true, it is added to the added to the returned list. For example:
returned list. For example:
``` ```
(fil (fn (a) (> a 100)) (20 150 30 200)) (fil (< 100) (20 150 30 200))
``` ```
would return `( 150 200 )`, as no other elements fit the condition `(< 100 n)`. would return `( 150 200 )`, as no other elements fit the condition `(< 100 n)`.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -191,12 +191,7 @@ void stringStruct(struct string* s, const Object* obj)
struct StructDef* def = getStructAt(so->definition); struct StructDef* def = getStructAt(so->definition);
for (int i = 0; i < def->fieldCount; i++) { for (int i = 0; i < def->fieldCount; i++) {
appendf(s, " \"%s\": ", def->names[i]); appendf(s, " %s: ", def->names[i]);
if (so->fields[i].type == TYPE_SYMBOL && so->fields[i].string == NULL) {
appendf(s, "null,");
continue;
}
int isString = so->fields[i].type == TYPE_STRING; int isString = so->fields[i].type == TYPE_STRING;
if (isString) { if (isString) {
appendf(s, "\""); appendf(s, "\"");

View File

@ -206,7 +206,7 @@ title "Structs"
check "Struct Definition" "(struct Post (title body))" "T" check "Struct Definition" "(struct Post (title body))" "T"
check "Building a struct"\ check "Building a struct"\
'(struct Post (title body)) (Post "A title" "The Body")'\ '(struct Post (title body)) (Post "A title" "The Body")'\
'{ "title": "A title", "body": "The Body" }' '{ title: "A title", body: "The Body" }'
check "Accessing struct fields"\ check "Accessing struct fields"\
"(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p.title p.body)"\ "(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p.title p.body)"\
"( TITLE BODY )" "( TITLE BODY )"