Hash join: Difference between revisions

m
→‎{{header|TXR}}: Drop @(do ...)
No edit summary
m (→‎{{header|TXR}}: Drop @(do ...))
Line 1,737:
Generic hash join. Arguments <code>left-key</code> and <code>right-key</code> are functions applied to the elements of the <code>left</code> and <code>right</code> sequences to retrieve the join key.
 
<lang txrlisp>(defvar age-name '((27 Jonah)
<lang txr>@(do
(2818 Alan)))
(defvar age-name '((27 Jonah)
(1828 AlanGlory)
(2818 GloryPopeye)
(1828 PopeyeAlan)))
(28 Alan)))
 
(defvar nemesis-name '((Jonah Whales)
(Jonah Spiders)
(Alan Ghosts)
(Alan Zombies)
(Glory Buffy)))
 
(defun hash-join (left left-key right right-key)
(let ((join-hash [group-by left-key left])) ;; hash phase
(append-each ((r-entry right)) ;; join phase
(collect-each ((l-entry [join-hash [right-key r-entry]]))
^(,l-entry ,r-entry)))))
 
(format t "~s\n" [hash-join age-name second nemesis-name first]))</lang>
</lang>
 
{{out}}
 
<pre>$ txr hash-join.txrtl
(((27 Jonah) (Jonah Whales)) ((27 Jonah) (Jonah Spiders)) ((18 Alan) (Alan Ghosts)) ((28 Alan) (Alan Ghosts)) ((18 Alan) (Alan Zombies)) ((28 Alan) (Alan Zombies)) ((28 Glory) (Glory Buffy)))</pre>
 
543

edits