I cannot say this is the easiest thing I have ever written. #lisp
(defun fizzbuzz-of (x)
(let* ((nos (scan-range))
(fizz-src (series 'fizz))
(buzz-src (series 'buzz))
(by3s (scan-range :from 0 :by 3))
(by5s (Scan-range :from 0 :by 5))
(fizzes (mask by3s))
(buzzes (mask by5s))
(fizz/buzzes (#Mlist (#Mand fizzes fizz-src)
(#Mand buzzes buzz-src))))
(or (collect (choose-if #'identity
(scan (collect-nth x fizz/buzzes))))
(list (collect-nth x nos)))))
Conversation
Notices
-
Embed this notice
screwlisp (screwtape@mastodon.sdf.org)'s status on Sunday, 17-Nov-2024 11:26:43 JST screwlisp -
Embed this notice
screwlisp (screwtape@mastodon.sdf.org)'s status on Sunday, 17-Nov-2024 11:29:00 JST screwlisp Who named this "lazy" ?
@fosskers was it you? -
Embed this notice
screwlisp (screwtape@mastodon.sdf.org)'s status on Sunday, 17-Nov-2024 11:51:03 JST screwlisp @fosskers
Ugh, it's 10x slower than this loop facility one.
(defun loopfizz-of (no)
(let ((res (loop :repeat (1+ no)
:for x :from 0 :by 1 :for y := '0 :then y :for z := '0 :then z
:when (eql x y) :do (incf y 3)
:When (eql x z) :do (incf z 5)
:finally (return (list x (decf y 3) (decf z 5))))))
(cond ((and (= (car res) (cadr res)) (= (car res) (caddr res))) '(fizz buzz))
((= (car res) (cadr res)) '(fizz)) ((= (car res) (caddr res)) '(buzz))
(:otherwise (butlast res 2))))) -
Embed this notice
screwlisp (screwtape@mastodon.sdf.org)'s status on Sunday, 17-Nov-2024 11:55:41 JST screwlisp @fosskers
(defun eg (x)
(let* ((nos (scan-range))
(fizz-src (series 'fizz))
(buzz-src (series 'buzz))
(by3s (scan-range :from 0 :by 3))
(by5s (Scan-range :from 0 :by 5))
(fizzes (mask by3s))
(buzzes (mask by5s))
(fizz/buzzes (#Mlist (#Mand fizzes fizz-src)
(#Mand buzzes buzz-src))))
(list (collect-nth x (#Mand fizzes fizz-src))
(collect-nth x (#Mand buzzes buzz-src))
(collect-nth x nos))))
Oh if I don't tell it to cons, it's faster than loop. -
Embed this notice
screwlisp (screwtape@mastodon.sdf.org)'s status on Sunday, 17-Nov-2024 12:43:44 JST screwlisp @CryogenicIce9
I used to always feel like I was being super fast when I was using it though. So it losing a race against The First Series Thing I Wrote Ever has me kind of sore as well!
Over here -> https://mastodon.sdf.org/@screwtape/113496220378967727
/ https://lispy-gopher-show.itch.io/lispmoo2/devlog/835106/richard-waters-series-and-lispmoo2
@fosskers -
Embed this notice
Nicola (cryogenicice9@mastodon.online)'s status on Sunday, 17-Nov-2024 12:43:45 JST Nicola @screwtape @fosskers I hate loop soooo much, every time I see it, it gnaws at me like an open wound
In conversation permalink -
Embed this notice
screwlisp (screwtape@mastodon.sdf.org)'s status on Thursday, 21-Nov-2024 11:41:11 JST screwlisp @fosskers oh, I guess so. It is an oddity that Series mandates lazy evaluation only for Series stuff, as compiled in between calling
(series::install :pkg :my-package)
<some lazy series functionality in :my-package>
(series::install :pkg :my-package :remove t)In conversation permalink -
Embed this notice
Colin (fosskers@m.fosskers.ca)'s status on Thursday, 21-Nov-2024 11:41:26 JST Colin @screwtape When I mentioned "laziness" in the Transducers README, I was referring to Haskell's notion of it. Namely, a first-class language feature that's built in to the compiler and affects everything.
In conversation permalink
-
Embed this notice