From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: calcium Newsgroups: gmane.lisp.guile.user Subject: Re: help : call function with args Date: Thu, 5 Apr 2018 11:42:08 +0200 Message-ID: References: <531867ae-fc67-35dc-e480-968678eed296@disroot.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1522921230 27807 195.159.176.226 (5 Apr 2018 09:40:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 5 Apr 2018 09:40:30 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 Cc: guile-user@gnu.org To: Thomas Morley Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Apr 05 11:40:25 2018 Return-path: Envelope-to: guile-user@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 1f41NY-00076n-L7 for guile-user@m.gmane.org; Thu, 05 Apr 2018 11:40:24 +0200 Original-Received: from localhost ([::1]:43928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f41Pc-0002t6-7O for guile-user@m.gmane.org; Thu, 05 Apr 2018 05:42:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f41PB-0002sg-7f for guile-user@gnu.org; Thu, 05 Apr 2018 05:42:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f41P7-00006e-84 for guile-user@gnu.org; Thu, 05 Apr 2018 05:42:05 -0400 Original-Received: from knopi.disroot.org ([178.21.23.139]:38614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f41P6-000060-Sy for guile-user@gnu.org; Thu, 05 Apr 2018 05:42:01 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id C8DA022BA2; Thu, 5 Apr 2018 11:41:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1522921318; bh=xHadGoiI5aRCEx/hftCdrF2OMCCDr1I6wbtSThQijb8=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=UABM5/o2oiBvVjt9zT67xcOgTV+SRJy/rx3NaAMFz1IjJmHiCVGpYOWBnKm8qSu0z aiVSV8U+2wke72d8jZH/U06E/JyIOVNAp408yY5Wq5kZrv5uipZ0On2zhx1zKMyUEg 32TVuXQ8ysyjUSlTkapvEtduh3yxok0l/7PmePWCfmM8gp9z5LjUpc6YELf+Z51Hp5 yfrDFTeKz0gXa178Dqqd+5T1zBW9HZKSHxJ3MXbZGDcLlmU9W1N9q/cveSmUBKTUD9 3OIPCYfDtlhflinsvsSxLOvOpcUokRpii3hjXLpqqsGT7V2oYe05pnamwGYBHd2KdB A4wbV6v/lUn8g== X-Virus-Scanned: Debian amavisd-new at disroot.org Original-Received: from knopi.disroot.org ([127.0.0.1]) by localhost (mail01.disroot.lan [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oOzLnHEsB-q0; Thu, 5 Apr 2018 11:41:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1522921317; bh=xHadGoiI5aRCEx/hftCdrF2OMCCDr1I6wbtSThQijb8=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=vKSUMTO3gPIvN4ljWSEzp/Bw2R4U3sMtH+HASlZnpSW9ZvdNufcMkz7Z4cQEDNCg5 FzJkrZFRRsqOlTXd90zSxYEhbn+74TgaM0DwOVHMm1FVrZ2zmmPr+BX2Ov2xbJilp5 d0NgFOFioJQ/0TAnOaUpGxQjzUVR6GLis3xJkk4G12fBFAVbY8dDEbcdqScynW1TZg 38YbKhfhQNGxhYw/dEl9Kh/iHK/050HTaGYJ0+emBioRlHJUT2rkiqVRhFF6COQwbn xvaTXT7vqMaTjC1+TAJ44XXFO062blJaFohtaIZPPGj5kuCIsb6vFV0fxB4gse+ZPF By0HT1QOb0KyQ== In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.21.23.139 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14530 Archived-At: > Not sure what you aim at. > Though, above seems to be easier with: > > (define (f . rest) (apply + rest)) > > (f) > -> 0 > (f 1 2 3) > -> 6 > (f 1 2 3 4 5 6 7 8 9 10) > -> 55 > > Cheers, > Harm > yes, it easier for this function, but when we have functions with different "types" like the one bellow , i find it nice to only call once the function, instead of copy-past the common args and then giving the different args for each cond branch. Although, the example that i give, it way more elegant and readable the second than the first, but i believes that sometimes the first can be more compact an elegant than the second one. (define lst (list 1 3 5 9 10 2 1 2 20 4 9 15)) ;;sort the list so that the biggest element is the first element ;;and the rest without a particular order. ;;write once the function (let sort ((preLst (cdr lst)) (postLst '()) (biggest (car lst))) (cond ((nil? preLst) (cons biggest postLst)) (else (let ((post (cons (car preLst) postLst)) (big biggest)) (cond ((> (car preLst) biggest) (set! big (car preLst)) (set! post (cons biggest postLst)))) (sort (cdr preLst) post big))))) ;; instead of writing (let sort ((preLst (cdr lst)) (postLst '()) (biggest (car lst))) (cond ((nil? preLst) (cons biggest postLst)) (else (cond ((> (car preLst) biggest) (sort (cdr preLst) ;; the common arg (cons biggest postLst) (car preLst))) (else (sort (cdr preLst) ;;the common arg (cons (car preLst) postLst) biggest)))))) Cheers, Calcium