HN user

createuniverses

73 karma
Posts1
Comments14
View on HN
Why GNU Emacs? 10 years ago

Live coding environments typically include a text editor. Sometimes as in the case of Praxis, its possible to change the behaviour of the text editor while you use it.

https://github.com/createuniverses/praxis

I wrote it for myself mainly, so a lot of the features are undocumented and hidden away. But you can have a look at fnkeys.lua, editor.lua and keymap.lua to get a general idea. These are in prods/syntax2015continued. You can bring these up in praxis and make whatever changes you like to the live system.

I like the idea of making it keyboard and buffer driven to an extreme, like the Commodore 64. For example, one simple technique I like is to "inject" code into the current buffer to place objects:

  function makeCamPosSaver()
    local x,y,z = getCamPos()
    x = math.floor(x)
    y = math.floor(y)
    z = math.floor(z)
    local s = "setCamPos("..x..","..y..","..z..")"
    print2(s)
  end
Then calling makeCamPosSaver injects a bit of code that will move the camera back where it was when you called it.

Another example: pressing F3 creates a new buffer where you are supposed to fill in a string with what you are searching for. When you run that buffer, it will switch to the old one that spawned it, and move the cursor to the next occurrence of the search string.

There are more creative ways to use this that others could come up with I'm sure.

Why "reproduce"? Don't produce the next generation of slaves. On balance, life is misery. Leave the unborn in peace.

I've wrangled a crazy way to have your cake and eat it too.

  do
    local state = 0
    function render()
      drawLine(0,5,0, 0,5,50*math.sin(state))
      state = state + math.pi * 0.03
    end
  end
To fiddle with the "state" variable from the outside:
  name,val = debug.getupvalue(render, 1)
  print(name) -- state
  print(val)  -- state's value

  debug.setupvalue(render, 1, 0) -- set state to 0
To find out how many upvalues are available:
  dt = debug.getinfo(render)
  print(dt.nups)
If you want to redefine render without disturbing state, you need to backup state and make a new closure with the new definition of render and the restored state:
  do
    local savedstate = {debug.getupvalue(render,1)}
    local state = savedstate[2]
    function render()
      local h = 5
      drawLine(0,h,0,50 * math.sin(state), h,0)
      state = state + math.pi * 0.06
    end
  end
I don't think its possible (or I don't know how) to redefine a function inside a closure. So just make a new closure and restore its state.

Thank you!

I need to make a video demonstrating the midi recording functionality (its implemented entirely in Lua). I need to keep it short, write a script that is succinct and to the point, use a decent microphone, keep it short, actually narrate the thing and most importantly, keep it short.

The whole thing is a repl with a graphical and audio engine at your disposal to use as you see fit. As well as writing your program iteratively in the "socratic" repl style, you are free to fluidly create whatever visualizations you wish along the way to help you. As well as this, if you split the process you have implemented into frames (a simple way is with coroutines or closures) you can make whatever visualization you prefer of your number crunching. For example, throw in some yield() calls in your program and every update() do a coroutine.resume(). In render() visualize the state of your program how you wish. The great thing about this is, as you change your program, the effect of your change will be reflected in what is rendered.

I can't help feeling that this attempt to render a previously excellent course more commercially viable by making it more superficially appealing for students is directly linked to this story: http://news.ycombinator.com/item?id=4785246

If everything is always forced to justify itself commercially, then everything will implode into a hideous, hollow caricature of itself. Everything becomes a flashy excercise in deceit and con artistry if it wants to survive. Quality and substance can never hope to win against marketing.