From de6a18813b71a3dc11feabb88fc6259d5a2e4a9a Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Sat, 30 Nov 2024 00:48:10 +0900 Subject: [PATCH] Implement `(send)` --- example.lsp | 9 ++++++--- global.go | 5 +++++ main.go | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/example.lsp b/example.lsp index 5a6f74e..28bd4b9 100644 --- a/example.lsp +++ b/example.lsp @@ -4,14 +4,17 @@ (while t (case (expect* 'timeout 10 "xxx" "yyy") ((0) - (sendln (string-append ctrlc "exit")) + (send ctrlc) + (sendln "exit") (return-from main nil) ) ((1) - (sendln (string-append ctrlc "rem")) + (send ctrlc) + (sendln "rem") ) ((-1) - (sendln (string-append ctrlc "exit")) + (send ctrlc) + (sendln "exit") (return-from main nil) ) ) diff --git a/global.go b/global.go index fa31793..43b36d8 100644 --- a/global.go +++ b/global.go @@ -21,6 +21,11 @@ func (g *Global) Close() { g.closer = nil } +func (g *Global) send(ctx context.Context, w *gmnlisp.World, arg gmnlisp.Node) (gmnlisp.Node, error) { + io.WriteString(g.term, arg.String()) + return gmnlisp.Null, nil +} + func (g *Global) sendln(ctx context.Context, w *gmnlisp.World, arg gmnlisp.Node) (gmnlisp.Node, error) { io.WriteString(g.term, arg.String()) g.term.Write([]byte{'\r'}) diff --git a/main.go b/main.go index f1c720e..88d64fa 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ func mains(args []string) error { lisp = lisp.Flet( gmnlisp.Functions{ + gmnlisp.NewSymbol("send"): gmnlisp.Function1(g.send), gmnlisp.NewSymbol("sendln"): gmnlisp.Function1(g.sendln), gmnlisp.NewSymbol("spawn"): &gmnlisp.Function{Min: 1, F: g.spawn}, gmnlisp.NewSymbol("expect*"): gmnlisp.SpecialF(g.expect),