From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "John Wiegley" Newsgroups: gmane.emacs.devel Subject: Re: Is there a function for auto currying in Elisp? Date: Thu, 21 Dec 2017 13:04:37 -0800 Message-ID: References: <87tvwki1oe.fsf@petton.fr> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1513890691 30099 195.159.176.226 (21 Dec 2017 21:11:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 21 Dec 2017 21:11:31 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (darwin) Cc: Nicolas Petton , Emacs Devel To: vlnx@mail.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 21 22:11:26 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eS87h-0007U6-MB for ged-emacs-devel@m.gmane.org; Thu, 21 Dec 2017 22:11:25 +0100 Original-Received: from localhost ([::1]:41640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS89g-0005lH-5K for ged-emacs-devel@m.gmane.org; Thu, 21 Dec 2017 16:13:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS83j-0001Ng-Gu for emacs-devel@gnu.org; Thu, 21 Dec 2017 16:07:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eS83g-0005pM-B4 for emacs-devel@gnu.org; Thu, 21 Dec 2017 16:07:19 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:60475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS83g-0005pF-7A; Thu, 21 Dec 2017 16:07:16 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:45857) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1eS83g-0004PV-0Y; Thu, 21 Dec 2017 16:07:16 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 3589E20AFD; Thu, 21 Dec 2017 16:07:15 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Thu, 21 Dec 2017 16:07:15 -0500 X-ME-Sender: Original-Received: from localhost (76-234-69-149.lightspeed.frokca.sbcglobal.net [76.234.69.149]) by mail.messagingengine.com (Postfix) with ESMTPA id B93C77E43A; Thu, 21 Dec 2017 16:07:14 -0500 (EST) In-Reply-To: (vlnx's message of "Thu, 21 Dec 2017 10:48:54 -0600") Mail-Followup-To: vlnx@mail.com, Nicolas Petton , Emacs Devel X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221319 Archived-At: >>>>> "v" == vlnx writes: v> Nicolas Petton writes: >> I've been looking for a function that would automatically curry its >> argument, but couldn't find it. Maybe I just missed it? v> This may be what you are looking for: v> #+BEGIN_SRC emacs-lisp v> (defun funcall-list (funcs list) v> "Apply `funcall' of each FUNCS on LIST, recursively defined" v> (if (car funcs) v> (funcall-list (cdr funcs) v> (funcall (car funcs) list)) v> list)) v> #+END_SRC Sometimes I also want: (defun traverse (f x) "Visit all nodes within the sexp X, apply F to its leaves." (cond ((consp x) (cons (traverse f (car x)) (traverse f (cdr x)))) ((listp x) (mapcar (apply-partially #'traverse f) x)) ((hash-table-p x) (maphash #'(lambda (key value) (puthash key (traverse f value) x)) x)) (t (funcall f x)))) Do we have a function already that visits every visitable "node" within a sexp? -- John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2