Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Currying considered useless

Name: Anonymous 2007-06-20 0:11 ID:OhxqYAeK

(defmacro p/ (f &rest body)
    (let ((args (gensym)))
        `(lambda (&rest ,args)
            (apply #',f (append ',body ,args)))))   


usage:

(mapcar (p/ + 1) '(1 2 3)) --> (2 3 4)

alternate syntax, with the help of a few read macros

(mapcar #[+ 1] '(1 2 3))

Name: Anonymous 2007-06-20 2:01 ID:F9WgWXl9

I would just like to give thanks and acknowledge a truly great historical figure who did his
best to help shape the world to what it is today. I'm talking of course about Adolf Hitler.
He looked ahead and saw over-population causing future global problems so he exterminated a
lot of the 'unnecessary' niches of human civilisation (eg: homosexuals gypsies and jews).
With his leadership Germany conquered a huge portion of the world and only failed in the end
because of inconvenient Allied attacks and the wealthy, well equipt but still incompetent USA
helping out. There is so much to say about this truly wonderful man so I think your homework
can be to research him and then you can show your appreciation for all the joy he helped to
bring to the world

Name: Anonymous 2007-06-20 3:02 ID:r/kkpsvY

(defun deep-find (item sequence)
  (
or (find item sequence)
      (
some (function identity) (mapcar
 (
lambda (x) (if (consp x) (deep-find item x)))
sequence
))))


(defun deep-substitute (newitem olditem sequence)
  (
mapcar
   (
lambda (x) (if (consp x) (deep-substitute newitem olditem x) x))
   (
substitute newitem olditem sequence)))

Name: Anonymous 2007-06-20 3:03 ID:r/kkpsvY

(set-macro-character #\] (get-macro-character #\) nil))

(set-macro-character #\[ (lambda (stream char)
 (
declare (ignore char))
 (
let ((body (read-delimited-list #\] stream t))
 (
x (gensym)))
 (
if (deep-find (quote _) body)
 (
let ((y (gensym))
 (
z (gensym)))
 (
sb-impl::backq-list (quote lambda) (sb-impl::backq-list x (quote &rest) y) (quote
)
(sb-impl::backq-list (quote let) (sb-impl::backq-list (sb-impl::backq-list z (sb-impl::backq-list (quote if) y (sb-impl::backq-list (quote cons) x y) x))) (quote
)
(deep-substitute z (quote _) body))))
 (
sb-impl::backq-list (quote lambda) (sb-impl::backq-list (quote &rest) x) (quote
)
(sb-impl::backq-list* (quote apply) (sb-impl::backq-list (quote function) (car body)) (quote
)
(sb-impl::backq-append (cdr body) (sb-impl::backq-list (quote
)
x))))))))

Name: Anonymous 2007-06-20 3:04 ID:r/kkpsvY


(set-macro-character #\[ (lambda (stream char)
               (declare (ignore char))
               (let ((body (read-delimited-list #\] stream t))
                 (x (gensym)))
                 (if (deep-find '_ body)
                 (let ((y (gensym))
                       (z (gensym)))
                   `(lambda (,x &rest ,y)
                      (let ((,z (if ,y (cons ,x ,y) ,x))) ;; compiler sometimes knows y is nil, and causes a compile note.. how can this be fixed?
                    ,(deep-substitute z '_ body))))
                 `(lambda (&rest ,x)
                    (apply (function ,(car body))
                       ,@(cdr body)
                       ,x))))))

Name: Anonymous 2007-06-20 3:05 ID:r/kkpsvY

module defines new syntax, square brackets

There are two cases, whether or not _ is present

[f a b c] => (lambda (&rest x) (apply #'f a b c x))
[f _ a b] => (lambda (x &rest y) (let ((z (if y (cons x y) x)) (apply #'f z a b))))

the idea with _ is you can use the variable as is, if the [] is called w/ a single parameter, but you use it as a list of parameters if [] is called with more than 1 parameter


Example usage:

;> (mapcar [cons 'x] '(1 2 3))
((X . 1) (X . 2) (X . 3))
;> (mapcar [cons _ 'x] '(1 2 3))
((1 . X) (2 . X) (3 . X))
;> (mapcar [cons (first _) (second _)] '(1 2 3) '(a b c))
((1 . A) (2 . B) (3 . C))
;> (mapcar [cons (second _) (first _)] '(1 2 3) '(a b c))
((A . 1) (B . 2) (C . 3))



possible .emacs addition:
(add-hook 'lisp-mode-hook
          (defun lisp-mode-more-brackets ()
             (modify-syntax-entry ?[ "(]  ")
             (modify-syntax-entry ?\] ")[  ")))

Name: Anonymous 2007-06-20 10:29 ID:fKEHF9sR

cool, it reminds me of the graham idea for arc (which must be the ultimate vaporware or sumthin)

what I don't like is _ referring to two different arguments. I'd rather use _1 and _2 or something like that instead.

Name: Anonymous 2007-06-20 11:13 ID:3SwGE3/0

in before reddit

Name: Anonymous 2007-06-20 11:38 ID:r/kkpsvY

>>7
Have you considered how horrible and un-lisp-like that is? Even worse than my macro..
Check out the essays on dreamsongs.org, its great reading and taught me a lot about style which are hard to pick up.

Name: Anonymous 2007-06-20 11:49 ID:fKEHF9sR

I have read a few essays from there... which one(s) do you mean, especifically?

Name: Anonymous 2007-06-20 13:23 ID:4gBT8zT6

Anyways, >>1, please listen to me. Not that it's really related to this thread. I went to /prog a while ago; you know, world4ch? Well anyways there were an insane number of Haskell programmers in there, and I couldn't post. Then, I googled for the Haskell homepage, and it had "PURELY FUNCTIONAL PROGRAMMING LANGUAGE" written on it. Oh, the stupidity. Those idiots. You don't use a programming language just because it s purely functional, fool. It's only referential transparency, FORCED NO SIDE EFFECTS for crying out loud. There're even companies using it. Company of 400 employees, all downloading some Haskell compiler, huh? How fucking nice. Alright, my manager's gonna use Haskell for the whole project. God I can't bear to watch. You people, I'll give you a damn purely functional language for FREE if you stop fagging up my /prog. /prog should be a bloody place. The tense atmosphere, where two guys on opposite sides of an open discussion can start a fight over VIM vs Emacs at any time, the stab-or-be-stabbed mentality, that's what's great about this place. Haskell fags should screw off and stay home. Anyways, I was about to discuss dynamic typing, and then the bastard beside me goes programming, with Haskell. Who in the world uses Haskell, you moron? I want to ask him, do you REALLY want to use Haskell? I want to interrogate him. I want to interrogate him for roughly an hour. Are you sure you don't just want to try saying Haskell? Coming from a expert programmer such as myself, the latest trend among us vets is this, multi-paradigm languages. That's right, multi-paradigm languages. This is the vet's way of programming. Multi-paradigm languages means more functionality than fappage. But on the other hand the theoretical correctness is a tad lower. This is the key. And then, it's powerful. This is unbeatable. However, if you try this then there is danger that you'll be marked by trolls from next time on; it s a double-edged sword. I can't recommend it to amateurs. What this all really means, though, is that you, >>1, should just stick with today's special.

Name: Anonymous 2007-06-20 13:28 ID:fKEHF9sR

delicious, pasta, etc.

Name: Anonymous 2009-01-14 15:06

Discuss

Name: Anonymous 2010-11-27 9:45

Name: Anonymous 2010-12-17 1:32

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2010-12-17 1:36

Erika once told me that Xarn is a bad boyfriend

Don't change these.
Name: Email:
Entire Thread Thread List