Advertisement
Guest User

Untitled

a guest
Aug 11th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. Date: 28 Jan 86 06:22:59 EST (Tue)
  2. From: ram@yale-ring
  3. Subject: Of growing code and diminishing hacks...
  4. Sender: ram%yale-ring%arpa.yale@edu.mit.lcs.mc
  5. To: t-discussion@arpa.yale, scheme@arpa.mit-mc
  6.  
  7. A SHORT BALLAD DEDICATED TO THE GROWTH OF PROGRAMS
  8. ==================================================
  9. by
  10. Ashwin Ram
  11.  
  12. This is a tale of a sorry quest
  13. To master pure code at the T guru's behest
  14. I enrolled in a class that appealing did seem
  15. For it promised to teach fine things like T3 and Scheme
  16.  
  17. The first day went fine; we learned of cells
  18. And symbols and lists and functions as well
  19. Lisp I had mastered and excited was I
  20. For to master T3 my hackstincts did cry
  21.  
  22. I sailed through the first week with no problems at all
  23. And I even said "closure" instead of "function call"
  24. Then said the master that ready were we
  25. To start real hacking instead of simple theory
  26.  
  27. Will you, said he, write me a function please
  28. That in lists would associate values with keys
  29. I went home and turned on my trusty Apollo
  30. And wrote a function whose definition follows:
  31.  
  32. (cdr (assq key a-list))
  33.  
  34. A one-liner I thought, fool that I was
  35. Just two simple calls without a COND clause
  36. But when I tried this function to run
  37. CDR didn't think that NIL was much fun
  38.  
  39. So I tried again like the good King of yore
  40. And of code I easily generated some more:
  41.  
  42. (cond ((assq key a-list) => cdr))
  43.  
  44. It got longer but purer, and it wasn't too bad
  45. But then COND ran out and that was quite sad
  46.  
  47. Well, that isn't hard to fix, I was told
  48. Just write some more code, my son, be bold
  49. Being young, not even a moment did I pause
  50. I stifled my instincts and added a clause
  51.  
  52. (cond ((assq key a-list) => cdr)
  53. (else nil))
  54.  
  55. Sometimes this worked and sometimes it broke
  56. I debugged and prayed and even had a stroke
  57. Many a guru tried valiantly to help
  58. But undefined datums their efforts did squelch.
  59.  
  60. I returneth once more to the great sage of T
  61. For no way out of the dilemma I could see
  62. He said it was easy -- more lines must I fill
  63. with code, for FALSE was no longer NIL.
  64.  
  65. (let ((val (assq key a-list)))
  66. (cond (val (cdr val))
  67. (else nil)))
  68.  
  69. You'd think by now I might be nearing the end
  70. Of my ballad which seems bad things to portend
  71. You'd think that we could all go home scot-free
  72. But COND eschewed VAL; it wanted #T
  73.  
  74. So I went back to the master and appealed once again
  75. I said, pardon me, but now I'm really insane
  76. He said, no you're not really going out of your head
  77. Instead of just VAL, you must use NOT NULL instead
  78.  
  79. (let ((val (assq key a-list)))
  80. (cond ((not (null? val)) (cdr val))
  81. (else nil)))
  82.  
  83. My song is over and I'm going home to bed
  84. With this ineffable feeling that I've been misled
  85. And just in case my point you have missed
  86. Somehow I preferred (CDR (ASSQ KEY A-LIST))
  87.  
  88. :-)
  89. ==================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement