-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSECONDFIRSTSTEPS
157 lines (121 loc) · 7.04 KB
/
SECONDFIRSTSTEPS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
As first first steps have been outlined in file INSTALL already, please
receive some suggestions here for what to do as second first steps:
1. show the available words (referred to as "the dictionary") by
executing "words":
`words` ( shows contents of a single wordlist only )
`words+` ( shows all wordlists in order, and additionally
compileonly, interpretonly, unresolved if populated)
You may discover a handful of functions (usually refered to as "words",
but sometimes "functions" in the context of yoda because that's how they're
represented under bash) you may not be familiar with. The flow control
statements "unless", "lest", "times" and "many" may belong to those,
and the plethora of stack words ending in a dollar character ($), as well
as the few words dealing with forward references.
We'll deal with those in time, for now there are more secondfirstish things
to explore.
2. compile a word and see what we wrought:
An ever popular sophisticated tool of computer science is called "hello world".
It outputs a specific text to console. With yoda this is one way how this can
be achieved:
`: hello "Hello, world!" type$ cr ;`
After entering and successful compilation (indicated by no error message, instead
an "ok" prompt shown), this just compiled word can be decompiled for viewing,
and executed. To decompile, enter:
`see hello`
The bash function that line was translated to is shown, along with a function name
which is clearly different from how we called it.
Execute this function by entering:
`hello`
At least does this different name not affect our ability to call the function by
by the name we gave it.
bash functions can't carry the same name, because they are more limited regarding
the set of letters considered legal for function names. In yoda, characters may
be used for naming new words against which bash would balk when trying to use those
for functions. Naming a word #### is entirely legal for yoda, while bash outrightly
refused to give function such a name. Therefore are all yoda names translated to
names bash can be more comfortable with.
3. yoda as shell
disabled by default, this can be switched on when needed:
`shell on`
alternatively, you can enter, for turning on the shell:
`+s`
as consequence will yoda pass on everything which it doesn't understand for execution
to bash, along with the remainder of the input line. Note that these commands aren't
executed in a subshell, but run within the same environment context as yoda does.
What that means can be demonstrated by these two commands:
`foo="bar"`
`echo "$foo"`
Disabling this shell mode again is done with:
`shell off`
or alternatively with:
`-s`
As with shell on, both yoda and shell execution capabilities are merged and available
at the same time, both can be used to augment each other.
Try, for an example, this:
`+s`
`many 3 secs page free`
What this will do is:
many - repeat remainder of the line until key pressed
3 secs - pause for 3 seconds
page - wipe screen and place cursor at start of screen
free - execute OS command to show memory use
Note that OS commands can also be executed while shell is off. But as those won't get
passed on automatically by yoda, they must be marked in a specific way. That's done
by prefixing them with a >, as in
`-s` f ( doesn't really matter, but shows that next line works anyway )
`3 times >sleep 1; >free`
Rather than passing the whole input line to bash, the ; acts as a command terminator
char after which further evaluation of input line is returned to yoda. Without ; still
the whole line ispassed as command arguments. Note that instead of >sleep 1; we
could again have used 1 secs here instead. The choice whether yoda or shell is charged
with execution is ours.
3a. exchange environment variables with shell
read a number from a bash environment variable:
`+s`
`var=123` \ set bash variable var to 123
`"var" env 2* .` \ read value of var, place on stack, multiply with 2, then output.
write the number on yoda stack into bash variable:
`1000 "var" >env` \ push 1000 to stack, then write to bash variable "var"
`echo "$var"` \ check result
read a string from bash variable:
`var="foobar"` \ assign string "foo" to bash variable var
`"var" env$` \ read string from var, place on string stack
`4 left$ type$` \ modify, then output string.
write string to bash variable:
`"bar" "var" >env$`
`echo "$var"`
each of these four words to exchange environment data, env, >env, env$ and >env$
thus expects the variable name as string on top of string stack.
env and >env then use the numeric stack for data i/o, while
env$ and >env$ fetch and place data from and on string stack.
4. loading a from file:
the word "from" is used for reading yoda source. When not loading a library,
"from" must be told where to load the file from, as accurate location of the
file to load.
assuming that our current directory (that is, the directory we were in when
quit was launched) is "yoda", there's probably a subdirectory named "tests"
in it which contains, among others, a recursive function to calculate fibonacci
numbers. That function is commonly used for demonstration and testing because
of its simplicity. To load that file, specifying its location, enter:
`from demo/fibo`
It will load, compile, and run, resulting in the output of some fibonacci numbers
followed by a decompiles listing of the code it generated.
Loading and executing a file doesn't need interactive mode. Instead it
is just as possible to load, compile and run a source file from command line,
then returning to it after execution (again assuming the current directory is
where yoda is located):
`yoda from demo/fibo`
5. looking at loaded / compiled files:
for a list of already loaded files, execute
`files`
if you have included the fibo file above, it will be shown too, with a number
on its left. That number is the "handle" which can be used to refer to this
file. Say it is 4, then this will display the contents of that file:
`4 list`
Should you want to open it in the configured editor, enter:
`4 edit`
Any word compiled from file can be opened in the editor:
`review boot` ( or whatever word you may be interested in instead )
`review fibo`
6. "My head is smoking - how do I exit?"
execute: `bye`