kellysmith12.21
2020-12-20 08:34:54

Is the grammar of patterns used by syntax-parse based on a particular formalism? It looks like <https://en.wikipedia.org/wiki/Boolean_grammar|boolean grammars>, but I don’t know if that’s just coincidence.


notjack
2020-12-20 09:49:29

I have yet to encounter a use case for mutable strings that justifies their existence


notjack
2020-12-20 09:50:34

finally got around to making a utility for chaining together multiple comparators


soegaard2
2020-12-20 10:55:37

Is this comparator-chain similar to chain=? ? https://srfi.schemers.org/srfi-67/srfi-67.html#node_idx_90


notjack
2020-12-20 10:57:13

No, that chain=? is doing something totally unrelated


notjack
2020-12-20 10:58:15

comparator-chain combines multiple comparators into a single comparator


laurent.orseau
2020-12-20 10:58:57

I’ve been reimplementing most of this recently, if only I had known!


laurent.orseau
2020-12-20 10:59:05

Thanks for this then!


notjack
2020-12-20 11:00:41

hmm, maybe I’ll add a reducer version of this


notjack
2020-12-20 11:01:47

(transduce (list ...) #:into (into-sorted? comparator #:descending? #true #:strict? #true))


laurent.orseau
2020-12-20 11:02:51

@soegaard2 The main difference IIUC with <https://github.com/Metaxal/bazaar/blob/master/order.rkt|my version> is that I use a partial order, i.e. the possible values of a comparison are &lt;, =, &gt;, #f where the latter means uncomparable


notjack
2020-12-20 11:03:48

what sort of stuff do you find yourself using partial orders for?


soegaard2
2020-12-20 11:04:08

Got it. I see that we chose a slightly different approach using refine-compare. I have forgotten most of this SRFI. The rationale at the time:


soegaard2
2020-12-20 11:04:42

It would have been natural to include something equivalent to comparator-chain though.


soegaard2
2020-12-20 11:05:57

I kind of like the idea of using #f to represent uncomparable.


laurent.orseau
2020-12-20 11:06:32

@notjack for compound objects


notjack
2020-12-20 11:08:07

whatcha mean?


laurent.orseau
2020-12-20 11:09:34

say (random example) you can compare the social-rank of animals in the same family, but it’s meaningless if they are from different family s


laurent.orseau
2020-12-20 11:09:59

Then you can create a social-order&lt;=&gt; comparator


laurent.orseau
2020-12-20 11:13:41

It’s also useful for numbers. You can define a number comparator based on the existing &lt; and compare with incomparable +nan.0 for free, since (&lt; x nan.0) is #f for every number x



notjack
2020-12-20 11:14:33

interesting, I’ve done that social-rank thing a few times but I made the comparator throw when given values from different families, since in my case that shouldn’t happen in normal code (like you shouldn’t be trying to make a sorted set of animals unless they’re all from the same family)


laurent.orseau
2020-12-20 11:16:24

and yet in Racket you can do (sort '(0 2 +nan.0 3) &lt;) :wink:


notjack
2020-12-20 11:16:37

yeah I’d want that to throw


notjack
2020-12-20 11:16:54

since if it happens something has gone drastically wrong somewhere


laurent.orseau
2020-12-20 11:46:37

Indeed, but that exception should the duty of sort, not of the comparator.


laurent.orseau
2020-12-20 13:15:11

I’m also using sets of canonical elements, where I want to keep only the <?-most elements. That is, i remove each element A for which there is in this set another element B s.t. B < A. Here I don’t want to throw an exception if A and B are not comparable.


laurent.orseau
2020-12-20 13:33:15

in bazaar this is named make-chain&lt;=&gt; https://github.com/Metaxal/bazaar/blob/master/order.rkt#L192 It takes as arguments ‘pairs’ of [comparator, extractor] and produces a new comparator.


laurent.orseau
2020-12-20 13:57:38

Interestingly the box-compare example in srfi/67 is a partial order :slightly_smiling_face:


soegaard2
2020-12-20 14:01:21

The srfi site has got some new features! https://srfi.schemers.org/?keywords=comparison


laurent.orseau
2020-12-20 14:14:06

re comparator-chain and refine-compare, bazaar/order has a make-chain&lt;=&gt; function to keep things curried and a chain-comparisons macro to keep things fast. Naming is hard :smile:


rokitna
2020-12-20 20:26:48

I’ve run into uses of several kinds of comparator, which makes it pretty hard to name things sometimes. One of the more exotic ones I’ve had in mind has results of the form “Well I can at least tell you these two are &lt;=, but I’m not sure if they’re &gt;= or not.” (This is the kind of result contract-stronger? can give.)


laurent.orseau
2020-12-20 21:09:17

Not sure I follow. If they are both &lt;= and &gt;=, I suppose this entails that they are = , right? If so, how is that different from a normal &lt;=? If not, then… uh… I’m at a loss


rokitna
2020-12-20 22:39:05

contract-stronger? tells you either that they’re known to be &lt;= or that they’re not known to be &lt;=; it never tells you they’re known to be not &lt;= (in other words, known to be either &gt; or incomparable)


sorawee
2020-12-21 07:26:42

Question about #%app:

If we override #%app, it looks like keyword argument calls will always take the slow path. Is this intentional?

E.g., consider:

#lang racket/base (require (rename-in racket/base [#%app racket:#%app])) (define-syntax-rule (#%app . xs) (racket:#%app . xs)) (define (function-name #:a a) 1) (function-name #:a 2)


sorawee
2020-12-21 07:27:46

If we comment define-syntax-rule, then the expanded code will contain:

(if (#%app variable-reference-constant? (#%variable-reference function-name3)) (#%app function-name temp4) (slow-path ...))


sorawee
2020-12-21 07:28:20

But with define-syntax-rule, the if expression is replaced with just (slow-path ...)


sorawee
2020-12-21 07:43:53

Also, curious why we need to test for variable-reference-constant? at runtime. Isn’t it possible to decide which branch to take at compile-time?


sorawee
2020-12-21 07:46:28

Ah, a better example is:

#lang racket/base (define (function-name #:a a) 1) (define-syntax-rule (test . xs) (#%app function-name . xs)) (test #:a 2)


sorawee
2020-12-21 07:46:58

Implicit #%app (comment #%app out) allows us to use the fast path


sorawee
2020-12-21 07:47:11

but explicit #%app forces us to use the slow path