From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lawrence Bottorff Newsgroups: gmane.lisp.guile.user Subject: Simulating rational number addition/subtraction Date: Wed, 24 Feb 2016 22:27:45 +0000 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2692638c7ce052c8b93aa X-Trace: ger.gmane.org 1456352883 12972 80.91.229.3 (24 Feb 2016 22:28:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 24 Feb 2016 22:28:03 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Feb 24 23:27:58 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aYhuY-000685-Aj for guile-user@m.gmane.org; Wed, 24 Feb 2016 23:27:58 +0100 Original-Received: from localhost ([::1]:38800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYhuX-0007GY-MT for guile-user@m.gmane.org; Wed, 24 Feb 2016 17:27:57 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYhuN-0007GG-PO for guile-user@gnu.org; Wed, 24 Feb 2016 17:27:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYhuM-0008R4-Tl for guile-user@gnu.org; Wed, 24 Feb 2016 17:27:47 -0500 Original-Received: from mail-lb0-x22e.google.com ([2a00:1450:4010:c04::22e]:34562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYhuM-0008QL-Li for guile-user@gnu.org; Wed, 24 Feb 2016 17:27:46 -0500 Original-Received: by mail-lb0-x22e.google.com with SMTP id of3so18825369lbc.1 for ; Wed, 24 Feb 2016 14:27:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Kekc6Qgvh6V82pG5bU0bqrhpaKu1za2QMbWzRi0tS5o=; b=drMdeGuvrg0noWCgSB174fN651CIrfSkDkYhGeHDsD/sj5iGV2n5A0rhrkkgTrHYRr nA6oLvtWefRYBGddC5QwfuLZx9uQNh580oaXeBisFslBshhMv2TutMNzt1Zf2ApVj7U+ PePIDEl/XYWzKXpr5Bi1aiByhwxgvnKHOC9bsxcrFmU0Xv7lF6hbzYYpgPnLr10KXDnJ W0Apnd6rpLhXJkDKGEKo5fMPLvUdtfZHz+UX193C3XIBe/BSiPbjxOgtKnbH5nQjIHGX a2g5T80pfvp+N8VppdMNqw0Dw2SvmV8SO/o4nJKerUost3h1vICAkH8I1VdmEbn2g6Cw Y8ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=Kekc6Qgvh6V82pG5bU0bqrhpaKu1za2QMbWzRi0tS5o=; b=Qz81A3zVgnQ4DveAzcZZvbVKeWaw0fNz+Tt/O6SBmwIUpDGzE+hQCkwv6FCbwX9WHG DVx60MLYanbrvBeb6G3rz9g7iDCnItAtmrvAOcR6Rj8n8Iygk3ADeiN9Y14RndRUwShV uGqxPyUcXYkhzSIrDwJu3fVLfBodACPLqLalDpHpNOf4wxC2hFp8yBLKabRP9HJsNZiQ RQ8ih1/RY/ShqCo3deBrjMmIs1bpUrPjnJcjI+yfQwpYo67UprdP1iWAL6rAqrTfsvIb xXrqvz17+gPl3McnM2RS22y8cxrq4J8qYYLxxShgE6Y4m6cVaSV2k++CcGLD9dwvEUOI fz3w== X-Gm-Message-State: AG10YOTNaNF+V2JYdWrsGVOOBv7vrxKdpOQLg04L/S7JBc7WJ9N4w/H9JjmmtE6KD/Cu7ondsq9z8EizqlM7Xw== X-Received: by 10.112.201.133 with SMTP id ka5mr11058975lbc.1.1456352865598; Wed, 24 Feb 2016 14:27:45 -0800 (PST) Original-Received: by 10.25.29.195 with HTTP; Wed, 24 Feb 2016 14:27:45 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::22e X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 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-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12441 Archived-At: --001a11c2692638c7ce052c8b93aa Content-Type: text/plain; charset=UTF-8 With guile (and a few other Schemes/Lisps) you can directly add fractions or rational numbers: (+ 1/2 1/12) => 7/12 It's like magic, no? Anyway, I'm trying -- for educational purposes -- to reproduce this functionality. But right out of the blocks I'm stuck trying to figure out how to handle incoming parameters. So far I've got (define (myrat a b) . . .) (define (myrat a b c d) . . .) where numerator and denominator are given separately, as well as (define (myrat . fracparams) . . .) which still has my basic problem, namely, can one parameter hold both parts of a rational number, then allow the numerator and denominator to be peeled off and worked on, i.e., something like (let ((num1 numepeeler(a)) (denom1 denompeeler(a) LB --001a11c2692638c7ce052c8b93aa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
With guile (and a few other Schemes/Lisps) you can directl= y add fractions or rational numbers:

(+ 1/2 1/12)=C2=A0<= /div>
=3D> 7/12

It's like magic, no? An= yway, I'm trying -- for educational purposes -- to reproduce this funct= ionality. But right out of the blocks I'm stuck trying to figure out ho= w to handle incoming parameters. So far I've got

(define (myrat a b)
=C2=A0 =C2=A0. . .)

(define (myrat a b c d)
=C2=A0 =C2=A0. . .)

where numerator and denominator are given separately, as well as=C2= =A0

(define (myrat . fracparams)
=C2=A0 = =C2=A0. . .)

which still has my basic problem, nam= ely, can one parameter hold both parts of a rational number, then allow the= numerator and denominator to be peeled off and worked on, i.e., something = like

(let ((num1 numepeeler(a))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0(denom1 denompeeler(a)=C2=A0

<= br>
LB
--001a11c2692638c7ce052c8b93aa--