Compare commits
8 Commits
live-readm
...
master
Author | SHA1 | Date |
---|---|---|
Sage Vaillancourt | e97746ce07 | |
Sage Vaillancourt | 8120889bfd | |
Sage Vaillancourt | f6f6a27689 | |
Sage Vaillancourt | 1ee494ebae | |
sage | df83b69ede | |
Sage Vaillancourt | 1df21f9094 | |
sage | 1295ed816f | |
sage | 737bd3b70f |
19
README.md
19
README.md
|
@ -1,4 +1,4 @@
|
|||
# PebbLisp
|
||||
# ![PebbLisp](https://git.sagev.space/sage/pebblisp/raw/branch/master/resources/images/pebblisp-logo-white.png)
|
||||
|
||||
A very basic LISP implementation with an interpreter and editor written for the Pebble.
|
||||
|
||||
|
@ -90,15 +90,14 @@ write:
|
|||
|
||||
Calling it is as simple as `(sq 5)`, which returns `25`.
|
||||
|
||||
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
|
||||
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
|
||||
element in a list:
|
||||
|
||||
```
|
||||
(map (fn (a) (* a a)) (1 2 3 5 8 13 21 34))
|
||||
```
|
||||
|
||||
This is particularly useful on a low-memory device like the Pebble, where it may be useful to avoid storing the named
|
||||
This is particularly valuable on a low-memory device like the Pebble, where it may be wise to avoid storing the named
|
||||
lambda object in the environment.
|
||||
|
||||
Lambdas may also have no arguments:
|
||||
|
@ -147,19 +146,19 @@ input list.
|
|||
|
||||
## 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`
|
||||
`fil` returns a filtered list, based on a given list and a given condition. The general form of a `fil`
|
||||
expression is
|
||||
|
||||
```
|
||||
(fil (partial-condition) (candidate-list))
|
||||
(fil (condition) (candidate-list))
|
||||
```
|
||||
|
||||
Each element in the candidate list is compared against the partial condition. If the comparison returns true, it is
|
||||
added to the returned list. For example:
|
||||
Each element in the candidate list is compared against the
|
||||
condition. If the comparison returns true, it is added to the
|
||||
returned list. For example:
|
||||
|
||||
```
|
||||
(fil (< 100) (20 150 30 200))
|
||||
(fil (fn (a) (> a 100)) (20 150 30 200))
|
||||
```
|
||||
|
||||
would return `( 150 200 )`, as no other elements fit the condition `(< 100 n)`.
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.7 KiB |
|
@ -191,7 +191,12 @@ void stringStruct(struct string* s, const Object* obj)
|
|||
|
||||
struct StructDef* def = getStructAt(so->definition);
|
||||
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;
|
||||
if (isString) {
|
||||
appendf(s, "\"");
|
||||
|
|
|
@ -206,7 +206,7 @@ title "Structs"
|
|||
check "Struct Definition" "(struct Post (title body))" "T"
|
||||
check "Building a struct"\
|
||||
'(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"\
|
||||
"(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p.title p.body)"\
|
||||
"( TITLE BODY )"
|
||||
|
|
Loading…
Reference in New Issue