Skip to content

Commit cf4e520

Browse files
authored
Merge pull request #19 from Shen-Language/lisp-form
Add support for literal code `lisp.` form
2 parents e9baed2 + 5bc669a commit cf4e520

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Updated to Shen Open Source Kernel 21.0.
1313
### Added
1414
- `make release` command that creates os-specific archive of compiled binaries.
1515
- `dict.kl` to list of KL imports.
16+
- `lisp.` form to embed literal Common Lisp code.
1617

1718
### Changed
1819
- `cond` now raises an error when no condition is true, instead of returning `[]`.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ This port acts as the standard implementation of the Shen language. It is also t
1616

1717
Bug reports, fixes and enhancements are welcome. If you intend to port Shen to another variety of Common Lisp, consider doing so as a pull request to this repo.
1818

19+
## Features
20+
21+
`shen-cl` supports calling underlying Common Lisp functions by prefixing them with `lisp.`.
22+
23+
```
24+
(lisp.sin 6.28)
25+
-0.0031853017931379904
26+
```
27+
28+
Common Lisp code can also be injected inline using the `(lisp. "COMMON LISP SYNTAX")` syntax. The `lisp.` form takes a single string as its argument. Also keep in mind that shen-cl puts Common Lisp into case-sensitive mode where CL functions and symbols are upper-case so they don't conflict with symbols defined for Shen.
29+
30+
```
31+
(lisp. "(SIN 6.28)")
32+
-0.0031853017931379904
33+
34+
(lisp. "(sin 6.28)")
35+
The function COMMON-LISP-USER::sin is undefined.
36+
```
37+
38+
The function `shen-cl.exit` is included, which takes a single integer argument, terminates the process, returning the argument as the exit code.
39+
1940
## Prerequisites
2041

2142
You will need to have recent versions of the Common Lisp implementations you want to work with installed and available as the `Makefile` requires. Installation is different depending on operating system.

src/backend.lsp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
(MAPCAR #'(LAMBDA (C) (shen.cond_code Locals C)) (CDR Expr))
7777
'((T (simple-error "No condition was true"))))))
7878

79+
; _ [lisp. Code | More] -> (if (and (string? Code) (empty? More))
80+
; (protect (READ-FROM-STRING Code))
81+
; (simple-error "Argument to lisp. must be a literal string"))
82+
((AND (CONSP Expr) (EQ 'lisp. (CAR Expr)))
83+
(IF (AND (STRINGP (CADR Expr)) (NULL (CDDR Expr)))
84+
(READ-FROM-STRING (CADR Expr))
85+
(simple-error "Argument to lisp. must be a literal string")))
86+
7987
; Params [F | X] ->
8088
; (let Arguments (protect (MAPCAR (/. Y (kl-to-lisp Params Y)) X))
8189
; (optimise-application
@@ -503,7 +511,7 @@
503511
(NULL (CDDDR Expr)))
504512
(CONS '>= (CDR Expr)))
505513

506-
; [less? X Y] -> [< X Y]
514+
; [less? X Y] -> [< X Y]
507515
((AND
508516
(CONSP Expr)
509517
(EQ 'shen.less? (CAR Expr))

0 commit comments

Comments
 (0)