Inconsistent allowed attr values #17

Closed
opened 2 years ago by lehitoskin · 4 comments

From the documentation and functions, the following lines conflict with one another:

(can-be-txexpr-attr-value? 'symbol)
#t
(can-be-txexpr-attrs? '((foo bar)))
#f
(can-be-txexpr-attrs? '((foo "bar")))
#t

At some point it seems that symbols were set to be invalid (or were always supposed to be invalid) attribute values.

(validate-txexpr '(tx ((foo bar)) baz (p bin)))
  validate-txexpr: attribute value is not a string
  attribute value: 'bar
  in: '(tx ((foo bar)) baz (p bin))
(validate-txexpr '(tx ((foo "bar")) baz (p bin)))
'(tx ((foo "bar")) baz (p bin))
(attr-join '(tx ((foo "bar")) baz (p bin)) 'key 'val)
  string-join: contract violation
  expected: (listof string?)
  given: '(val)
From the documentation and functions, the following lines conflict with one another: ```racket (can-be-txexpr-attr-value? 'symbol) #t (can-be-txexpr-attrs? '((foo bar))) #f (can-be-txexpr-attrs? '((foo "bar"))) #t ``` At some point it seems that symbols were set to be invalid (or were always supposed to be invalid) attribute values. ```racket (validate-txexpr '(tx ((foo bar)) baz (p bin))) validate-txexpr: attribute value is not a string attribute value: 'bar in: '(tx ((foo bar)) baz (p bin)) (validate-txexpr '(tx ((foo "bar")) baz (p bin))) '(tx ((foo "bar")) baz (p bin)) (attr-join '(tx ((foo "bar")) baz (p bin)) 'key 'val) string-join: contract violation expected: (listof string?) given: '(val) ```
Owner

So which one needs to change for the results to make sense?

(can-be-txexpr-attr-value? 'symbol)

should be #false not #true?

So which one needs to change for the results to make sense? ``` (can-be-txexpr-attr-value? 'symbol) ``` should be `#false` not `#true`?
Poster

It seems like much of the goal of the package is to have interoperability with XML via xexpr->string and so on, which will fail if a txexpr-attr-value has anything other than a string. The easiest change would be to make (can-be-txexpr-attr-value? 'symbol) return #f.

It seems like much of the goal of the package is to have interoperability with XML via `xexpr->string` and so on, which will fail if a txexpr-attr-value has anything other than a string. The easiest change would be to make `(can-be-txexpr-attr-value? 'symbol)` return `#f`.
Owner

On closer inspection, I don’t consider this a bug. There is a difference between the predicate txexpr-attr-value? (which indeed rejects symbols) and can-be-txexpr-attr-value? which, as the name suggests, represents things that can be losslessly converted to Racket strings. Including symbols.

The point of the distinction is to use the more lenient predicate (can-be-txexpr-attr-value?) on input values, and the stricter predicate (txexpr-attr-value?) on output.

On closer inspection, I don’t consider this a bug. There is a difference between the predicate `txexpr-attr-value?` (which indeed rejects symbols) and `can-be-txexpr-attr-value?` which, as the name suggests, represents things that can be losslessly converted to Racket strings. Including symbols. The point of the distinction is to use the more lenient predicate (`can-be-txexpr-attr-value?`) on input values, and the stricter predicate (`txexpr-attr-value?`) on output.
mbutterick closed this issue 2 years ago
Owner

PS I do think your example

(attr-join '(tx ((foo "bar")) baz (p bin)) 'key 'val)

Should work, so I will fix that.

PS I do think your example ``` (attr-join '(tx ((foo "bar")) baz (p bin)) 'key 'val) ``` Should work, so I will fix that.
mbutterick reopened this issue 2 years ago
mbutterick closed this issue 2 years ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 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#17
Loading…
There is no content yet.