Skip to content

Commit

Permalink
Added (version) primitive to REPL
Browse files Browse the repository at this point in the history
This is also usable in the interpreter, but it is designed for
the REPL

This closes #122.
  • Loading branch information
skx committed Jan 25, 2023
1 parent 97d7c80 commit 355f77d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions .yalrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
;;
;; OK now we're done, show a banner and launch the REPL
;;
(print "YAL version %s" (version))
(print "This is ~/.yalrc on %s - %s %s" (trim (hostname)) (os) (arch) )
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var (
LISP *eval.Eval
)

// versionFn is the implementation of the (version) primitive.
func versionFn(env *env.Environment, args []primitive.Primitive) primitive.Primitive {
return primitive.String(version)
}

// create handles the setup of our global interpreter and environment.
//
// The standard-library will be loaded, and os.args will be populated.
Expand All @@ -50,6 +55,13 @@ func create() {
// Populate the default primitives
builtins.PopulateEnvironment(ENV)

// Add the (version) function
ENV.Set("version",
&primitive.Procedure{
F: versionFn,
Help: "Return the version of the interpreter.\n\nSee-also: arch, os",
Args: []primitive.Symbol{}})

// Build up a list of the command-line arguments
args := primitive.List{}

Expand Down Expand Up @@ -264,7 +276,6 @@ func main() {
//
// No arguments mean this is our REPL
//
fmt.Printf("YAL version %s\n", version)
reader := bufio.NewReader(os.Stdin)

//
Expand Down

0 comments on commit 355f77d

Please sign in to comment.