- `length` will take a string, an IOHandle representing a string-buf, or a list. In the case of a string it will return the number of _runes_ as thought of in golang. Loosely equivalent to characters, rather than bytes.
- Standard read and write procedures work with the IOHandle returned from `string-make-buf`
<li><code>(string->number [string] [[base: number]])</code>: <code>number</code> If a non-decimal base is supplied, the input string will be parsed as an integer and any flaoting point value will be floored</li>
<li><code>(string->list [string] [[value]])</code>: <code>list</code> (splits the first string at each instance of value, cast as a string)</li>
<li><code>(string->md5 [string])</code>: <code>string</code> If a non-decimal base is supplied, the input string will be parsed as an integer and any flaoting point value will be floored</li>
<li><code>(string->sha256 [string])</code>: <code>string</code> If a non-decimal base is supplied, the input string will be parsed as an integer and any flaoting point value will be floored</li>
returnexception("insufficient number of arguments given to 'string->number'")
}
ifs,ok:=a[0].(string);ok{
s,ok:=a[0].(string)
if!ok{
returnexception("'string->number' expects a string as its first argument, a non-string value was given")
}
base:=10
iflen(a)>1{
b,ok2:=a[1].(number)
if!ok2{
returnexception("'string->number' expects a number representing the base being used for number parsing as its second argument, a non-number value was given")
}
base=int(b)
}
iflen(a)==1||base==10{
f,err:=strconv.ParseFloat(s,64)
iferr==nil{
returnnumber(f)
}
}
returnfalse
i,err:=strconv.ParseInt(s,base,64)
iferr!=nil{
returnexception("'string->number' was unable to parse the given string into a valid number")
}
returnnumber(i)
},
"string-fields":func(a...expression)expression{
iflen(a)==0{
@ -1374,7 +1393,9 @@ var stdLibrary = vars{
if!ok2{
returnexception("'number->string' expected a number as its second argument, a non-number value was given")
}
returnstrconv.FormatInt(int64(n),int(base))
ifbase!=10{
returnstrconv.FormatInt(int64(n),int(base))
}
}
returnstrconv.FormatFloat(float64(n),'f',-1,64)
},
@ -1479,9 +1500,7 @@ var stdLibrary = vars{
returnexception("'file-open-read' expects a filepath as a string, a non-string value was given")
@ -11,3 +11,190 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
`
consthistoryFilenamestring="slope-repl.history"
varusageStrings=map[string]string{
"quote":"(quote [expression...]) => bool",
"if":"(if [condition: expression] [#t-branch: expression] [[#f-branch: expression]]) => value\n\nAny value other than #f is considered true for the purposes of the `condition`, any expression given to `if` as a `condition` will be evaluated and its value will be taken as truthy or falsy by the above truthiness rule",
"and":"(and [expression...]) => bool",
"or":"(or [expression...]) => bool",
"cond":"(cond [([condition: expression] [#t-branch: expression])...]) => value\n\nWill evaluate each condition in turn and evaluate to the #t-branch of the first condition that is truthy. If no condition is truthy then an empty list will be returned. The value `else` is a sepcial case allowed as the final condition expression, the #t-branch of this condition list will be returned if no other condition is found to be truthy",
"set!":"(set! [var-name: symbol] [value|expression|procedure]) => value | expression | procedure\n\nReturns the value that var-name was set to, in addition to creating the var symbol and setting it to the given value. Only an existing variable can be set with `set!`, trying to set a non-existant variable will result in an exception. `set!` will always set the value for the variable in the nearest scope",
"define":"(define [var-name] [value|expression|procedure]) => value | expression | procedure\n\nReturns the value that var-name was set to, in addition to creating the var symbol and setting it to the given value. Define is lexically scoped (using define within a lambda will create a variable that is only visible to that lambda and its child scopes, but not to any parent scopes)",
"lambda":"(lambda [([[argument: sumbol...]])] [expression...]) => procedure\n\n`lambda` creates its own scope and any define statements within the lambda will be scoped to the lambda (available to it and any child scopes)",
"begin":"(begin [expression...]) => value\n\nEvaluates a series of expressions and returns the value of the last expression that is evaluated",
"begin0":"(begin [expression...]) => value\n\nEvaluates a series of expressions and returns the value of the first expression that is evaluated",
"filter":"(filter [test: procedure] [list]) => list\n\nThe test procedure supplied to filter should take one value and will have its return value treated as a bool. Any value in the list that returns a true when fed to the test procedure will be added to the list that filter returns",
"load":"(load [filepath: string...]) => symbol\n\n`load` will open the file represented by filepath and evaluate its contents as slope code. It will run any code within the file. `load` can accept a relative reference, which will be treated as relative to the current working directory. Any `define` statements within the laoded file will result in the symbol getting added to the global environment",
"load-mod":"(load-mod [module-name: string...]) => symbol\n\n`load-mod` will search the module path for the given module. If found, the file 'main.slo' within the module folder will be parsed. Arbitrary code will not be executed, only `define`, `load-mod`, and `load-mod-file` statements will be evaluated",
"load-mod-file":"(load-mod-file [filepath: string]) => symbol\n\n`load-mod-file` is used within modules to do a relative load of files that are a part of the module, but are not 'main.slo'. The same evaluation rules as `load-mod` apply to `load-mod-file`",
"number->string":"(number->string [number] [[base: number]]) => string\n\nThe value for `base` defaults to 10 (decimal). If a value other than 10 is provided then the number will be parsed as an integer and output in the given base. If the value for `base` is 10 or is not given, the number will be parsed as a floating point number",
"rand":"(rand [[max]] [[min]]) => number\n\nIf no arguments are given `rand` will produce a floating point number between 0 and 1. If only `max` is given, `rand` will produce a floating point number between 0 and `max`. If `max` and `min` are both given, `rand` will produce a floating point number between `min` and `max`. `max` is always exclusive (the value produced will always be less than `max`), while `min` is inclusize. To obtain integers use `floor`, `ceil`, or `round` on the result or `rand`",
">":"(> [number] [number]) => bool",
">=":"(>= [number] [number]) => bool",
"<":"(< [number] [number]) => bool",
"<=":"(<= [number] [number]) => bool",
"not":"(not [value]) => bool\n\n`not` will invert the truthiness of the value it is given",
"equal?":"(equal? [value] [value]) => bool",
"number?":"(number? [value]) => bool",
"string?":"(string? [value]) => bool",
"bool?":"(bool? [value]) => bool",
"symbol?":"(symbol? [value]) => bool",
"pair?":"(pair? [value]) => bool",
"list?":"(list? [value]) => bool",
"null?":"(null? [value]) => bool",
"procedure?":"(procedure? [value]) => bool",
"atom?":"(atom? [value]) => bool",
"assoc?":"(assoc? [value]) => bool",
"io-handle?":"(io-handle? [value]) => bool",
"string-buf?":"(string-buf? [value]) => bool",
"~bool":"(~bool [value]) => bool\n\n`~bool` will convert a given value to a boolean value using a looser set of rules than `if` would normally use: 0, 0.0, the empty list, an empty string, and a closed io-handle will be considered falsy (in addition to #f)",
"map":"(map [procedure] [list...]) => list\n\n`map` will pass the values of each list as arguments to the given prcedure and a new list will be created from the results. If multiple lists are given, they should be the same length and their values will be given as arguments such that the first argument of each list will be provided to the given procedure (as two arguments in the case of two lists, three in the case of three etc), then the second argument, and so on",
"for-each":"(for-each [procedure] [list...]) => empty-list\n\nWorks via the same rules as `map`, but is used specifically for its side effects, rather than return values. See `map` for further details",