From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: unusual let binding (of lp) - in function element->xml from sxml simple Date: Sun, 4 Feb 2024 09:46:24 +0100 Message-ID: References: <87zfwhrzcq.fsf@softland> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25808"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Andreas Reuleaux Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Feb 04 09:47:28 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 1rWY9v-0006Tz-Sl for guile-user@m.gmane-mx.org; Sun, 04 Feb 2024 09:47:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWY9E-0007n2-Je; Sun, 04 Feb 2024 03:46:44 -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 1rWY9B-0007mk-Lj for guile-user@gnu.org; Sun, 04 Feb 2024 03:46:42 -0500 Original-Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWY97-0004TT-Em for guile-user@gnu.org; Sun, 04 Feb 2024 03:46:41 -0500 Original-Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-78552105081so107246985a.3 for ; Sun, 04 Feb 2024 00:46:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707036396; x=1707641196; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=P9j2m/wE9gqA5u9RX5H7ftd5V4fKL6aiEvwiRl9s27g=; b=WIX2YJEXaQBRZeB5pT3NsYEFvSjdHqtGSaDFPnzQQ/1NwgqJPjcx/44g+bsm6rA0vA 0WOqlybCAnQXxyKsbb8qhD+ztohz0anHj4vXgexpqeRdEh3FrcKWrMaDtSYWfdQyHLgD DqBuzSanYRh0K9Ne2B8Z9oaKDa/41X+zcy2pdT56ojn3Z3vjDFJGeLxEYwrqaXsS2XZM 9cuog36tPcbvXhkr7IIo89UtJRo0ptxXGI7DDM3P9vvAffI4gdey6jTPsdtdpR4mLMgZ 3t5N373sjFeYTNwwZh1IHCBdwTsGouP1P7pXo9wIq9NVuCna9q2rZXI7uQtCadhEP+GO TjUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707036396; x=1707641196; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=P9j2m/wE9gqA5u9RX5H7ftd5V4fKL6aiEvwiRl9s27g=; b=P90JTAJtZDbxug/bWVpl+J7btYCfGTMy8i1PuP2dJYva1mzNb14ALaBPlK+gLvsA4B RyTqETP6iXowExCs1hsj1xbGfSy1u0Zcbe424s3fhDLHceah5m6zrEDWBAa3FUYYjqO2 tEjKPwviPDZLWxrkw9JCvywaQpHNIT7/hywKkKSQEXIBV501CHBgUp3Z0kwQLacZmh4L dB/zzdxTvENe5ydDE6fzq2AWfnbEDGxAfByauP56CZs1SBpoy6rOCu8L0H3RPmx/cCS5 ue3g2/6ycRuMgyqpTj9kPvLCyfM8V/B3Fnud2Criy1ceJzvAp4sxlFWMnKE9OUCZlL70 3E5A== X-Gm-Message-State: AOJu0YwMimIKP0vS4RaB+YF8fv806mNFjiUqPO9oLhZQR6MHRcrq96qc MEqQlFtXvYtjWmOCfkMmyhArLyubHDgzNT4mrsnwoxquFJTDGb/cwuHLPL88c0Am9RBhSOFaYeJ 89UOs6vKfN+2tDU1s3U838J41ppw= X-Google-Smtp-Source: AGHT+IHTbr2KpFg7w5BsxPmKiYypdZXVx7yDezHV+e0fSbs+sjC6ciEtqc4wBerKljjCPElTuUZhZtuBHKsLyj80FAQ= X-Received: by 2002:a05:6214:400c:b0:68c:9dca:18f6 with SMTP id kd12-20020a056214400c00b0068c9dca18f6mr1084241qvb.11.1707036395794; Sun, 04 Feb 2024 00:46:35 -0800 (PST) In-Reply-To: <87zfwhrzcq.fsf@softland> Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=damien.mattei@gmail.com; helo=mail-qk1-x72c.google.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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:19435 Archived-At: Hi Andreas, a good explanation is here: https://stackoverflow.com/questions/31909121/how-does-the-named-let-in-the-= form-of-a-loop-work personally i avoid to use it, as i can do the same with internal definitions . regards, Damien On Sat, Feb 3, 2024 at 10:49=E2=80=AFPM Andreas Reuleaux wro= te: > 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 " (display tag port) > (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 > role=3D"strong">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' > > > > > > > > > > > > > > >