Adds devnull

master
sloum 2 years ago
parent b5c466c354
commit e48bce4b56

@ -107,12 +107,12 @@ There are a number of special forms in the language that will allow, for example
#### Values
`PI`, `E`, `sys-args`, `stdin`, `stdout`, `stderr`
`PI`, `E`, `sys-args`, `stdin`, `stdout`, `stderr`, `devnull`
`sys-args` is populated with the arguments run at the command line, similar to C's `argv`
`stdin`, `stdout`, and `stderr` are set at runtime to an open IOHandle representing each IO file. This makes it easy to read or write to any of them the same as you would any other file (by passing the IOHandle to the reader/writer).
`stdin`, `stdout`, `stderr`, and `devnull` are set at runtime to an open IOHandle representing each IO file. This makes it easy to use them the same as you would any other file (by passing the IOHandle to the reader/writer).
#### Number related

@ -537,3 +537,8 @@ func stringParensMatch(s string) bool {
// parser will handle erroring
return true
}
func GetFile(path string) *os.File {
devnull, _ := os.OpenFile(path, os.O_WRONLY, 0755)
return devnull
}

@ -29,7 +29,7 @@ var stdLibrary = vars{
"stdin": &IOHandle{os.Stdin, true, "file (read-only)"},
"stdout": &IOHandle{os.Stdout, true, "file (write-only)"},
"stderr": &IOHandle{os.Stderr, true, "file (write-only)"},
// TODO add /dev/null
"devnull": &IOHandle{GetFile(os.DevNull), true, "file (write-only)"},
// TODO add env pathlookup
"PI": number(math.Pi),
"E": number(math.E),
@ -346,9 +346,8 @@ var stdLibrary = vars{
return true
},
"assoc": func(a ...expression) expression {
// TODO change this to just 'assoc' and combine get and set based on number of params
if len(a) < 2 {
return exception("'assoc-get' expected two values, a list and a value; insufficient arguments were given")
return exception("'assoc' expected at least two values, a list and a value; insufficient arguments were given")
}
list, ok := a[0].([]expression)
if !ok {

Loading…
Cancel
Save