Open BookOwl opened 8 years ago
Maybe a stdlib
branch?
OK, then when it's ready we can merge it into master
Here's some example code to get hyped up about:
10 range ', ' ljoin print
-> 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0
10 range { 5 * } lmap ', ' ljoin print
-> 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0
3 range { string ', he said.' concat print } lforeach
-> 1.0, he said.
-> 2.0, he said.
-> 3.0, he said.
HYPE-OVERLOAD!!! (Thank you mr PullJosh)
dat overload doe.
Any ideas for useful functions?
Anything and everything in Python's standard library. :package:
+1
implementing threading is such a pain
I could probably make some of this stuff.
6 11 'hello world' lettersof print
-> world
Will Stack get a Python API for exposing Python functions to Stack?
(also libraries can be made using import
but this will have round-import/multiple import issues noo)
Yes it already does.
:package:
hello.py
:
def hello(interpeter, stack, scopes, stream):
print("Hello world!")
# This also works if you don't need to deal with data:
def hello(*args):
print("Hello world!")
module = {
"hello": hello
}
tmp.stack
:
`hello import
hello
-> Hello world!
I actually used it in my slen
function (though I think that's now a built-in op..?):
_strings.py
:
def _len(interpeter, stack, scopes, stream):
val = stack.pop()
tok = interpeter.Token(
TYPE='num', VAL=len(val.VAL))
stack.append(tok)
module = {
"_len": _len
}
strings.stack
:
`_strings import
...
{
/*
Get the length of a string.
Syntax:
<str> slen
Examples:
'Hello world!' slen -> 12
'There are ' 'Word: ' input slen string
' letters in that word.' concat concat print
*/
_len
} `slen def
Another example is the randomness
lib:
randomness.py
:
# Note this file isn't named "random" - if it were, it would not let me
# import Python's builtin random module!
import random
def _random(interpeter, stack, scopes, stream):
tok = interpeter.Token(
TYPE='num', VAL=random.randint(0, 1000000) / 1000000.0)
stack.append(tok)
module = {
"random": _random
}
Wow you can extend stack xD awesome
Time to make BSD sockets wrapper (or maybe python library socket
because that is just a wrapper around BSD sockets/winsock)
BSD sockets makes sense because a sock is a int
but I guess you could use the py-obj
token type
(well yesterday I tried atom because of it's GFM rendering and git integration — now I'm going to try it out.) (edit: maybe I'll use IDLE since it's official Python IDE and is a full-featured IDE.)
BTW what is the stream object?
Also will there be a high-level stack inheriting from Array which on .pop()
does the error handling?
Also can we use the report_error
function?
Edit: I have to import stack.interpeter
:confused:
There's some MAJOR bugs with importing...
I have example.stack
and test.stack
in the same directory.
example.stack
imports test.stack
.
I get the error:
The file /test.stack does not exist!
when running example.stack
.
Why is it looking in /
and not the current directory?
I may have fixed that among other importing bugs in #23.
Strange that it should append /
to the start though. What's your code?
You don't need to import stack.interpeter
, because of the arguments given to a Python function whenever it's called in Stack:
def foo(interpeter, stack, scopes, stream):
...
interpeter is the stack.interpeter
module.
stack is the data stack.
scopes are the data scopes.
stream is the command stream.
Ok thanks!
Stack needs a standard library of modules written in Stack, like the ones @liam4 have made.