An entertaining use of del

For users of dfns, both novice and expert

An entertaining use of del

Postby paulmansour on Sun Jul 07, 2013 8:31 pm

So late last night in an attempt to come up with a quick and dirty object-oriented framework for building up HTML, I wrote this:

Code: Select all
Add←{
     ⍺←⎕THIS
     e t←(2=≡⍵)⊃(⍵'')⍵
     e≡'':⍺⊣⍺.Content,←⊂t
     s←⎕NS''
     s.Element←e
     s.Content←(0=⍴t)⊃(,⊂t)t
     s.Add←∇
     0=⍺.⎕NC'Content':s
     ⍺.Content,←s
     s
 }


I particularly enjoyed line 7:

      s.Add←∇

I have not seen this use of del anywhere in the dfns namespace that I could find.

This little dfn lets me write:

      h←Add 'html'
b←h.Add 'body'
h1←b.Add 'h1' 'My Heading'
h1.class←'MyClass'
h1.id←'MyID'


Which then can be turned into HTML with an appropriately coded render function:

      Render h
<html><body><h1 class="MyClass" id="MyID">My Heading</h1></body></
html>
paulmansour
 
Posts: 262
Joined: Fri Oct 03, 2008 4:14 pm

Re: An entertaining use of del

Postby StefanoLanzavecchia on Mon Jul 08, 2013 11:57 am

Very nice!
User avatar
StefanoLanzavecchia
 
Posts: 61
Joined: Fri Oct 03, 2008 9:37 am


Return to Functional Programming

Who is online

Users browsing this forum: No registered users and 1 guest