arithmetic: Port to Mes.

* gash/arithmetic.scm (define-module): Import SRFI 14.
* gash/eval.scm (eval-arithmetic): New procedure.
(word->qword): Use it to abstract away the differences in 'eval'
between Guile and Mes.
This commit is contained in:
Timothy Sample 2022-11-08 15:54:38 -06:00
parent 2b44788598
commit 1b5ba1e9ec
2 changed files with 14 additions and 3 deletions

View File

@ -21,6 +21,7 @@
#:use-module (ice-9 match)
#:use-module (ice-9 receive)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-14)
#:use-module (srfi srfi-26)
#:use-module (system base lalr)
#:export (read-arithmetic))

View File

@ -36,6 +36,17 @@
;;;
;;; Code:
(cond-expand
(mes
(define (eval-arithmetic expr)
(eval `(begin (number->string ,expr))
(current-environment))))
(else
(define (eval-arithmetic expr)
(eval `(begin (use-modules (gash environment))
(number->string ,expr))
(interaction-environment)))))
(define eval-cmd-sub
(make-parameter (lambda (exps) (throw 'eval-cmd-sub-unset))))
@ -55,9 +66,8 @@ and arithmetic substitions."
((eval-cmd-sub) exps))
(('<sh-arithmetic> word)
(let* ((arithmetic (expand-word word #:output 'string))
(expr `(begin (use-modules (gash environment))
(number->string ,(read-arithmetic arithmetic)))))
(eval expr (interaction-environment))))
(expr (read-arithmetic arithmetic)))
(eval-arithmetic expr)))
(('<sh-ref> name)
(parameter-ref name ""))
(('<sh-ref-or> name default)