xexpr/c-like variants of txexpr-*? #16

Closed
opened 3 years ago by bluebear94 · 2 comments
bluebear94 commented 3 years ago (Migrated from github.com)

The xml library provides a contract called xexpr/c, which gives a better error message than xexpr? when passed in a non-X-expression:

> (define/contract not-an-xexpr xexpr/c '(b "hello " ("world") 42))
; not-an-xexpr: broke its own contract;
;  Not an Xexpr. Expected a symbol as the element name, given "world"
; Context:
; '(b "hello " ("world") 42)
;   in: xexpr/c
;   contract from: (definition not-an-xexpr)
;   blaming: (definition not-an-xexpr)
;    (assuming the contract is correct)
;   at: readline-input:14:17
; [,bt for context]

I'd like to see such contracts for the txexpr-*? predicates. If making one for all of them is too hard, then I'd be satisfied with just seeing txexpr/c.

The xml library provides a contract called [`xexpr/c`](https://docs.racket-lang.org/xml/index.html#%28def._%28%28lib._xml%2Fprivate%2Fxexpr-core..rkt%29._xexpr%2Fc%29%29), which gives a better error message than `xexpr?` when passed in a non-X-expression: ``` > (define/contract not-an-xexpr xexpr/c '(b "hello " ("world") 42)) ; not-an-xexpr: broke its own contract; ; Not an Xexpr. Expected a symbol as the element name, given "world" ; Context: ; '(b "hello " ("world") 42) ; in: xexpr/c ; contract from: (definition not-an-xexpr) ; blaming: (definition not-an-xexpr) ; (assuming the contract is correct) ; at: readline-input:14:17 ; [,bt for context] ``` I'd like to see such contracts for the `txexpr-*?` predicates. If making one for all of them is too hard, then I'd be satisfied with just seeing `txexpr/c`.
mbutterick commented 3 years ago (Migrated from github.com)

I agree the xexpr/c error message is better. At times I have thought about adapting that code for txexpr/c. I never got around to it, obviously. I’m unlikely to do so, since I consider my work on this project complete.

I suggest making an add-on package for txexpr that adds this function. If it works well, I would consider adding it to the main txexpr package.

I agree the `xexpr/c` error message is better. At times I have thought about adapting that code for `txexpr/c`. I never got around to it, obviously. I’m unlikely to do so, since I consider my work on this project complete. I suggest making an add-on package for `txexpr` that adds this function. If it works well, I would consider adding it to the main `txexpr` package.
mbutterick commented 2 years ago (Migrated from github.com)

Closing due to inactivity.

Closing due to inactivity.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/txexpr#16
Loading…
There is no content yet.