From nobody Tue Feb 23 17:04:08 2021 Authentication-Results: mail-b.sr.ht; dkim=pass header.d=hagelb-org.20150623.gappssmtp.com header.i=@hagelb-org.20150623.gappssmtp.com Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mail-b.sr.ht (Postfix) with ESMTPS id 6985D11EFF8 for <~technomancy/fennel@lists.sr.ht>; Tue, 23 Feb 2021 17:04:08 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id j24so6237015pfi.2 for <~technomancy/fennel@lists.sr.ht>; Tue, 23 Feb 2021 09:04:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hagelb-org.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=Hsp1HiX4SF5L4IBoIeq24cAnacRB9pj3PlKEyZ0gtu4=; b=JlJJJxQNnAJGFA8XTMbdjVDzEVmE1UavtzUzglWy5HpLAUuGj5ZczuxiX6/UwWf5tb EaFMLl6ZYBmjNCea8Vi1VsPryktOQwZaNh1Jhw0EN+48mcFdCMxZ2dEJ6RFSfq+meIBk gWtcvaJPqMrSgsbSmU7iP9Tkjevr8GVAj2mdB/6rfUT7pMMVgDVdUDlw4tfBxe75TzoH A1mWRWxBR2YTClljKb86I+2migJQv0E3thwmfuhDRr41mFQHSdIx+cXJF+yZg++qyfTM nkDpnbYXh7oupDq7qQdjMio3h/To1HfAYKjOagVtqrXnAtktbSZ44n8XqjQZby09jegt NerA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=Hsp1HiX4SF5L4IBoIeq24cAnacRB9pj3PlKEyZ0gtu4=; b=m/gkOUJKaUsQ/yrpxzuqTvoMO9AKsN66v2c5FlSs1QW1uXU+zqYzUSagRYukj/4PyM H4j4uzIW3qTnvfaJngJb83EBaR0kRlz8jc540N8ayOF80nJnIYPcrYxWQVEx8bf2kP23 3x4e0cZqizkH6kY7Z/Te1kVCLBdn3qvJhoWcBOwb2/5vFRenEY9pcx7XLGp00mgp1/LS 0uDzWLY19HdpjvtdQ/HyuQeqYBXTWvhr/KHVO5slD+Hqbnph6xIQpQ2+NzESsBtcKha/ NRcL1OqLYamFFWYXX+QI9dXAe28rJo63QbmyZQb4THYbTMTE+MH6aeomIpYIzIUKjmEG th/g== X-Gm-Message-State: AOAM530YwSdu3wdGAm8E0gWYV+nD7V2VJszm6W3aQF5IdwdJmc82HUEH Sekx+uHZL6VhzPWWYtcAwY6Idh9LSJO1+g== X-Google-Smtp-Source: ABdhPJzXiVmB3V3KmdPn6dHJ8u+kOXXkj5KCTMk2alxgEZXOTjUtBu2+8c4uYoBeQoWYE5RYGoaeng== X-Received: by 2002:a63:1e4b:: with SMTP id p11mr25779026pgm.301.1614099846755; Tue, 23 Feb 2021 09:04:06 -0800 (PST) Received: from whirlwind (174-21-85-198.tukw.qwest.net. [174.21.85.198]) by smtp.gmail.com with ESMTPSA id gm13sm3997332pjb.47.2021.02.23.09.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 09:04:05 -0800 (PST) References: <20210222102113.151545-1-andreyorst@gmail.com> User-agent: mu4e 1.0; emacs 26.1 From: Phil Hagelberg To: Andrey Listopadov Cc: ~technomancy/fennel@lists.sr.ht Subject: Re: [PATCH] implement new prefix syntax for match macro In-reply-to: <20210222102113.151545-1-andreyorst@gmail.com> Date: Tue, 23 Feb 2021 09:04:02 -0800 Message-ID: <87im6i1zst.fsf@whirlwind> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --=-=-= Content-Type: text/plain This looks great; thanks! Andrey Listopadov writes: > I've added tests for the new syntax, and ensured that all old tests > pass. I've also removed old syntax from the reference.md. It is still > accessible and will continue to work, but I think we should encourage > to use prefix notation by default. It might be a good idea to keep a brief mention of the old style in just in case people come across some old code and want to know why it works, similar to how require-macros is mentioned but is advised against. (In fact, the parallels to require-macros are strong because import-macros also expands to code which uses the old deprecated form.) > -**Note:**: The `match` macro can be used in place of the `if-let` macro > -from Clojure. The reason Fennel doesn't have `if-let` is that `match` > -makes it redundant. > +**Note:**: The `match` macro can be used in place of the `if-some` > +macro from Clojure. The reason Fennel doesn't have `if-some` is that > +`match` makes it redundant. We talked about this on IRC but I think we should keep this as-is because if-let is a frequently asked question and no one has yet asked about if-some, even though if-some has a behavior closer to match. > +;; Construction of old match syntax from new syntax I prefer this implementation to the other one as well. One point of clarification though; it seems that the compiler output of this macro will double-up (or triple-up, etc) the body associated with any pattern that uses `or`. Is this true of the other implementation as well? Also I think it would be good to be a little more explicit in the comments that the `match*` function strictly implements a version of `match` that does not support `where` clauses and that the implementation of `where` is handled below. > +(fn transform-cond [cond] > + ;; Transforms `where` cond into sequence of `match` guards. > + ;; > + ;; pat => [pat] > + ;; (where pat guard) => [(pat ? guard)] > + ;; (where (or pat1 pat2) guard) => [(pat1 ? guard) (pat2 ? guard)] > + (if (and (list? cond) (= (tostring (. cond 1)) :where)) > + (let [second (. cond 2)] > + (if (and (list? second) > + (= (tostring (. second 1)) :or)) This should be able to use = on a symbol now that we have the __eq metamethod. > +(fn match** [val ...] Let's internally name this function `match-where` to make it clearer that the `where` support is why it's a separate function. > +Syntax: > + > +(match data-expression > + pattern body > + (where pattern guard guards*) body > + (where (or pattern patterns*) guard guards*) body > + else-body)" Let's avoid mentioning the `else-body` argument. It's supported but I think it's better if we don't mention it and encourage people to match against `_` instead. Thanks for working on this! I'm looking forward to using the new functionality in my pattern matches. =) -Phil --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEEICQrrLvpWtoi0K/XgIoz03nIBsMFAmA1NYMACgkQgIoz03nI BsNPPgwAk+s3zMVmVx5xu2tF4oXhh913vRWXJIqtUgPndp1LsyUiMDWYLVLqCJEP MskWuzPVlT9JJZVR30OGzKPMfZg2ZugqiiK1uHrsNlD1XEpmKV/ZmVkbEZzIud16 r09qjD33yTequb2Azas22jxt+QkVI6G5iVwpnBXnUuWPQKdAQ5JGIHiXFYpcAZCa 5DhPxOBz4uvEBKaUHNmEyQpob5aN3whkkZ0vl1+qT/ainYKcR+vKFCKk7CbVXklu OAKrlMkSmwNo/ZXSKUXq6tkjqcTQyEJ1EG8A/f1ILl1eSfFtFE4apZmMWVR/yOuk pvj0Q/KuhJbEXsHLJpO0QTX70vcEEXxxRu+swIId2daUrxa8GV8p3lS3Sz4G4JrD 3RlstO1LwtFyyfLPFGLqCVGWRpEBF3+eZCFUB3NgTU7LlDvoDM6DtUEQD5eltfXQ ua1BSnFKmZObBHyDij57snY1I7bB5wwFZdNgcjKhKBjsvGGa5WojTnbonRRTIkHx LoU5mn63 =18gt -----END PGP SIGNATURE----- --=-=-=--