Advertisement
Guest User

Untitled

a guest
May 27th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. keyword :: io.prompt('Enter search keyword: ')
  2.  
  3. results :: server.find_results(type:'node', keyword:keyword)
  4.  
  5. ; This is actually a pretty sweet but basic hack.
  6. ; ``function`` operates in the caller's scope and eats the next object, after
  7. ; checking that it is a code literal.
  8. ; (NOTE: may change this requirement to permit constructs such as
  9. ; ``code :: manipulate_code({blah() does() this()}) function(`a, `b) code``)
  10. ; If it is, ``function`` saves the code object and returns a new function that
  11. ; injects variables based upon the args passed to ``function`` and the function
  12. ; call and then executes the saved code object in a new scope.
  13. results.sort(key:(function(`r) {r.similarity}))
  14.  
  15. ; A similar thing goes on here as to above, except that there is no new scope
  16. ; and the code is repeatedly re-run in the parent scope with just one variable
  17. ; re-set each time; the variable is populated using co-operative control flow
  18. ; passing with the passed function. When the function returns, the loops ends
  19. ; and the variable is cleaned up.
  20. foreach(`r, results.iter) {
  21. io.print(r.prettify())
  22. }
  23.  
  24. ; Another sweet hack that allows some really interesting if-else constructs.
  25. ; Basic operation is pretty obvious, but what about elifs, or at least elses?
  26. ; ``if``, ``elif``, and ``else`` set a parent-scope variable upon exit (to
  27. ; allow nesting) that tells whether or not the condition was met.
  28. ; following ``elif``s or ``else``s will know whether or not execution is
  29. ; desired by inspecting that flag.
  30.  
  31. if(verbose?) {
  32. io.print(server.debug_info())
  33. }
  34. else() {
  35. io.print('done.')
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement