Conversation
| end) | ||
|
|
||
| it('can consist of built-in words', function() | ||
| assert.are.same({ 1, 1, 1 }, forth.evaluate(': dup-twice dup dup ;1 dup-twice')) |
There was a problem hiding this comment.
| assert.are.same({ 1, 1, 1 }, forth.evaluate(': dup-twice dup dup ;1 dup-twice')) | |
| assert.are.same({ 1, 1, 1 }, forth.evaluate(': dup-twice dup dup ; 1 dup-twice')) |
Actual Forth is extremely word-oriented, where ;1 can be an actual command. ; should be a distinct word.
There was a problem hiding this comment.
Ah, thank you, I didn't know that. Do you think it makes sense to take instructions as an array of instructions instead of a concatenated string?
There was a problem hiding this comment.
That's what other tracks do. Having a single string of instructions will make the definition processing slightly more difficult: start with a : and process words until you get to ; -- in most other tracks, you get an array element where the string starts with : and ends with ;.
There was a problem hiding this comment.
Thanks. I modeled this after how Crystal did it and didn't think to check elsewhere.
| for chunk in s:gmatch('[^;]+') do | ||
| eval_chunk(chunk, stack, user_words) |
There was a problem hiding this comment.
In case you don't know, ; is not a statement separator, it is only the terminating word of a : definition. Newlines in forth are just spaces.
You'll probably want to trim leading whitespace from the chunk.
There was a problem hiding this comment.
Thanks, this is great feedback. All I know about forth I learned from doing this exercise in another language so I appreciate the tips.
There was a problem hiding this comment.
All I know about forth I learned from doing this exercise
Me too until I did the 8th track.
Co-authored-by: Glenn Jackman <jackman@pythian.com>
|
It's exciting to get new Lua exercises. Thanks for doing it. |
No description provided.