From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andreas Reuleaux Newsgroups: gmane.lisp.guile.user Subject: unusual let binding (of lp) - in function element->xml from sxml simple Date: Sat, 03 Feb 2024 21:51:01 +0000 Message-ID: <87zfwhrzcq.fsf@softland> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26006"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Feb 03 22:49:20 2024 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rWNt1-0006YS-6L for guile-user@m.gmane-mx.org; Sat, 03 Feb 2024 22:49:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWNsV-0006KZ-AF; Sat, 03 Feb 2024 16:48:47 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWNsT-0006Jz-EF for guile-user@gnu.org; Sat, 03 Feb 2024 16:48:45 -0500 Original-Received: from sender4-of-o50.zoho.com ([136.143.188.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rWNsO-00032G-IL for guile-user@gnu.org; Sat, 03 Feb 2024 16:48:45 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1706996915; cv=none; d=zohomail.com; s=zohoarc; b=OOtPpoJ3ziW7bPsjVeFQ8U7hgeJPCeUlgPaObVWtVutbEgWKCM/WJmMUNqtAF1Bfglt5jj9qhiLjxx26Mtk/u23oZGoW4Ow+yBKVgKFEoTy8Pzkppv7Nq7nJPnSooQw/paaGrKgyDgyJrw4V53A3TaaTTayvxjb2tD4nK2IrSvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706996915; h=Content-Type:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=MoN/u0rwb+JrjsIYHrHe6vNazTDgWrk3YaPnV8/nQGQ=; b=gwz8ZgKZ+TRX1SGuKYrpaK0mX19FmgZemFjN83Ccb5UQjU+1dtEwQCp2Dout9YOfjVWGS4PPx3fYj+a2FecrQvm6/EFVjIMifK/mbf4pRLLbtvu0pwCyIXprR7o/wKqMuCTjIqgvfBtSHc/WSpe/dWoPzfZkV444bCXTsIZzOtU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=a-rx.info; spf=pass smtp.mailfrom=rx@a-rx.info; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1706996915; s=zoho; d=a-rx.info; i=rx@a-rx.info; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Type:Message-Id:Reply-To:Cc; bh=MoN/u0rwb+JrjsIYHrHe6vNazTDgWrk3YaPnV8/nQGQ=; b=Xl2NguUultz5HduTM31KJRt5PCal1lX2cDEJavAOM8vOiY0PxNcQf8LzUdCE9Awg PhLKngIrjkCvBQ3/2I2V+w7v8DPiu0R2cthPc+Bw0e4JWdrOP8jR1IELHf6kPvm2bHE BNrNy7gFZQhf3rEoHfprDRH7gStdCrVUsE7zSPwk= Original-Received: from softland (148.252.128.76 [148.252.128.76]) by mx.zohomail.com with SMTPS id 170699691385394.07774251842204; Sat, 3 Feb 2024 13:48:33 -0800 (PST) Original-Received: from rx by softland with local (Exim 4.97) (envelope-from ) id 1rWNuh-000000001RC-0Bf7 for guile-user@gnu.org; Sat, 03 Feb 2024 21:51:03 +0000 X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.50; envelope-from=rx@a-rx.info; helo=sender4-of-o50.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19431 Archived-At: Hi, I have a hard time understanding the let binding lp ... in the function element->xml - from module sxml simple - repeated here for convenience. --8<---------------cut here---------------start------------->8--- (define (element->xml tag attrs body port) (check-name tag) (display #\< port) (display tag port) (if attrs (let lp ((attrs attrs)) (if (pair? attrs) (let ((attr (car attrs))) (display #\space port) (if (pair? attr) (attribute->xml (car attr) (cdr attr) port) (error "bad attribute" tag attr)) (lp (cdr attrs))) (if (not (null? attrs)) (error "bad attributes" tag attrs))))) (if (pair? body) (begin (display #\> port) (let lp ((body body)) (cond ((pair? body) (sxml->xml (car body) port) (lp (cdr body))) ((null? body) (display "" port)) (else (error "bad element body" tag body))))) (display " />" port))) --8<---------------cut here---------------end--------------->8--- Some background: sxml simple is - as the name implies - simple (or should be so). - It's implements * functions for parsing xml to s-expression xml->sxml, ... * and functions for serializing sxml to xml sxml->xml, ... (and among them: element->xml, as above) This second task (group of functions) is even simpler (than the parsing stuff) - I would say. Now these function (sxml->xml, element->xml) work for me: I can test them with some simple s-expression foo for example --8<---------------cut here---------------start------------->8--- (define foo '(d:para (d:emphasis (@ (role "strong")) "system analyst") " for " (d:link (@ (xl:href "http://www.blah.com")) (d:emphasis (@ (role "strong")) "Blah")) " in Berlin, and so on")) --8<---------------cut here---------------end--------------->8--- --8<---------------cut here---------------start------------->8--- scheme@(guile-user) [13]> (sxml->xml foo) system analyst for Blah in Berlin, and so on --8<---------------cut here---------------end--------------->8--- sxml->xml making use of element->xml above. Now with regards to the binding / usage of lp above: it is bound / used several times: (let lp ((attrs attrs)) ... let lp be a function that ... does what? (lp (cdr attrs))) now call this function with (cdr attrs). What does it do? set attrs to (cdr attrs)? then similar below (let lp ((body body)) ... ??? (lp (cdr body))) ??? For one thing I am used to (let bindings body) with bindings being of the form ((x 'foo) (y 'bar)) (i.e. bind x with 'foo, y with 'bar when executing body) for example, lp is not of this style. Maybe if there is just one variable bound one can shortcut this to let x 'foo body Is this what's going on above? And if so: then lp is bound to a list of one pair? : ((attrs attrs)) how come can we call this as a function then later. And if attrs is a function (which I doubt) that what is the application of attrs to attrs? Anyway: confused. - Thanks in advanc, A'