Closed puripuri2100 closed 4 years ago
Thanks for suggestion.
However, at least currently I’m not so willing to add these primitives. It seems to me that they should be implemented as ordinary user- or package-level functions, not provided as primitives; it would be simpler to make users or packages responsible for encoding/decoding values (by using satysfi-base
, for example) than to add somewhat duplicated primitives.
Adding these functions as primitive seems to cause a subtle cumbersome problem: assume the functions are added as primitives, and consider the following fragment of a program:
let () = register-cross-reference-int `foo` 42 in
get-cross-reference `foo`
Which of the following behaviors do you expect this program will take on?
None
(without any information that `foo`
is indeed associated with an integer value).Some(`42`)
or something like that (i.e., an entry encoded from an integer will be mistakenly decoded into a string).I think this is not so trivial. For now, avoiding this kind of problem and keep the language spec smaller seems to be a safer choice IMHO. Do you have nonetheless a strong motivation to add the functions as primitives, not as package-level functions?
I agree with that point and suggestion. We can implement with these functions. ex.
val register-cross-reference-int : int -> string -> unit
val get-cross-reference-int : string -> int option
let register-cross-reference-int value label =
register-cross-reference label (Int.to-string value)
let get-cross-reference-int label =
match get-cross-reference label with
| None -> None
| Some(s) -> Int.of-string-opt s
I sent PR with the same content to satysfi-base.
Please close this issue.
I want to write value of
int
orbool
in dump file.Can you add the following primitives?
register-cross-reference-int : string -> int -> unit
get-cross-reference-int : string -> int option
probe-cross-reference-int : string -> int option
register-cross-reference-bool : string -> bool -> unit
get-cross-reference-bool : string -> bool option
probe-cross-reference-bool : string -> int option