Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, in my own toy concatenative language, define is just a regular procedure. It takes two arguments off the stack. The first is a pointer to the name, the second is a pointer to a quotation with the definition body. It intentionally looks Forth-like but it's different under the hood:

    [ dup + ]      \ writes a lambda function to heap and push ptr
      : double ;   \ : writes the next symbol as a string to heap and push ptr
                   \ ; is define, writes definition into dict
The reason Forth did it the classic Forth way originally, I suspect, is because Forth's parser needs to be told to switch modes. Stop executing words directly and start compiling them. There isn't really anywhere to store a temporary string, so you need to tell it to start writing into the dictionary entry before you give it the string. In my language, using [ ] for quotations starts writing to the heap, which is also where strings go. This has the same practical effect.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: