Ron Toland
About Canadian Adventures Keeping Score Archive Photos Replies Also on Micro.blog
  • Seven More Languages in Seven Weeks: Factor

    Continuing on to the next language in the book: Factor.

    Factor is…strange, and often frustrating. Where Lua felt simple and easy, Factor feels simple but hard.

    Its concatenative syntax looks clean, just a list of words written out in order, but reading it requires you to keep a mental stack in your head at all times, so you can predict what the code does.

    Here’s what I learned:

    Day One

    • not functions, words
    • pull and push onto the stack
    • no operator precedence, the math words are applied in order like everything else
    • whitespace is significant
    • not anonymous functions: quotations
    • `if` needs quotations as the true and false branches
    • data pushed onto stack can become "out of reach" when more data gets pushed onto it (ex: store a string, and then a number, the number is all you can reach)
    • the `.` word becomes critical, then, for seeing the result of operations without pushing new values on the stack
    • also have shuffle words for just this purpose (manipulating the stack)
    • help documentation crashes; no listing online for how to get word docs in listener (plenty for vocab help, but that doesn't help me)
    • factor is really hard to google for

    Day Two

    • word definitions must list how many values they take from the stack and how many they put back
    • names in those definitions are not args, since they are arbitrary (not used in the word code itself)
    • named global vars: symbols (have get and set; aka getters and setters)
    • standalone code imports NOTHING, have to pull in all needed vocabularies by hand
    • really, really hate the factor documentation
    • for example, claims strings implement the sequence protocol, but that's not exactly true...can't use "suffix" on a string, for example

    Day Three

    • not maps, TUPLES
    • auto-magically created getters and setters for all
    • often just use f for an empty value
    • is nice to be able to just write out lists of functions and not have to worry about explicit names for their arguments all over the place
    • floats can be an issue in tests without explicit casting (no types for functions, just values from the stack)
    • lots of example projects (games, etc) in the extra/ folder of the factor install
    → 6:00 AM, Oct 12
  • Seven More Languages in Seven Weeks: Lua

    Realized I haven’t learned any new programming languages in a while, so I picked up a copy of Seven More Languages in Seven Weeks.

    Each chapter covers a different language. They’re broken up into ‘Days’, with each day’s exercises digging deeper into the language.

    Here’s what I learned about the first language in the book, Lua:

    Day One

    Just a dip into basic syntax.
    • table based
    • embeddable
    • whitespace doesn't matter
    • no integers, only floating-point (!)
    • comparison operators will not coerce their arguments, so you can't do =42 < '43'
    • functions are first class
    • has tail-call-optimization (!)
    • extra args are ignored
    • omitted args just get nil
    • variables are global by default (!)
    • can use anything as key in table, including functions
    • array indexes start at 1 (!)

    Day Two

    Multithreading and OOP.
    • no multithreading, no threads at all
    • coroutines will only ever run on one core, so have to handle blocking and unblocking them manually
    • explicit over implicit, i guess?
    • since can use functions as values in tables, can build entire OO system from scratch using (self) passed in as first value to those functions
    • coroutines can also get you memoization, since yielding means the state of the fn is saved and resumed later
    • modules: can choose what gets exported, via another table at the bottom

    Day Three

    A very cool project -- build a midi player in Lua with C++ interop -- that was incredibly frustrating to get working. Nothing in the chapter was helpful. Learned more about C++ and Mac OS X audio than Lua.
    • had to add Homebrew's Lua include directory (/usr/local/Cellar/lua/5.2.4_3/include) into include_directories command in CMakeLists.txt file
    • when compiling play.cpp, linker couldn't find lua libs, so had to invoke the command by hand (after reading ld manual) with brew lua lib directory added to its search path via -L
    • basically, add this to CMakeFiles/play.dir/link.txt: -L /usr/local/Cellar/lua/5.2.4_3/lib -L /usr/local/Cellar/rtmidi/2.1.1/lib
    • adding those -L declarations will ensure make will find the right lib directories when doing its ld invocation (linking)
    • also had to go into the Audio Midi Setup utility and set the IAC Driver to device is online in order for any open ports to show up
    • AND then needed to be sure was running the Simplesynth application with the input set to the IAC Driver, to be able to hear the notes
    → 6:00 AM, Sep 21
  • RSS
  • JSON Feed
  • Surprise me!