chris613
2019-3-11 09:02:42

@plragde i think i read that clojure’s type system allows for defining types as predicates ???


chris613
2019-3-11 09:07:51

very possibly miss remembering but i think clojures type stuff is based on the “specs” that are possible in clojure (and racket) however i very may well be getting totally confused ont hat!!! lol


hoshom
2019-3-11 10:38:35

@chris613 clojure’s specs are like Racket’s contracts


hoshom
2019-3-11 10:38:41

they aren’t types


chris613
2019-3-11 10:39:26

ahhhhh maybe i missed something, i thought clojures “type” system was essentially an introspection of the specs to make sure they were compatable


samth
2019-3-11 14:54:38

@plragde I’m not sure what you’re suggesting. What is this technology?


lexi.lambda
2019-3-11 15:15:13

@samth I think “the technology” in that sentence was just referring to the prior mention of systems like Coq and Agda (and dependently typed languages in general).


lexi.lambda
2019-3-11 15:15:51

Which in turn was answering @isomorphisms’s question.


pocmatos
2019-3-11 20:37:21

I might be blocked today but I just noticed something in the contract docs that I can’t find an example for. There’s this contract in the docs: (integer? string? ... integer? . -> . any) but I can’t find any function definition that satisfies the contract. The reason I am surprised is because I didn’t think having domain contracts after ... would work. A quick grep in racket code shows the use of ... in -> contracts is very rare and one with a domain contract after ... is non-existent except for the occurence in the documentation.


notjack
2019-3-11 20:40:43

@pocmatos I don’t know what’s up with that specific doc example, but as background info: I think the support for ... in -> contracts was added sometime in the last couple of years, and it’s not well advertised in the docs. So a lot of code doesn’t use it. However, I use it all the time in my code and I wish ->* and ->i supported it too.


pocmatos
2019-3-11 20:41:20

whoops just noticed I posted this in beginners. should be fine, i guess.


pocmatos
2019-3-11 20:42:25

@notjack yes, i noticed it’s recent but still can’t find a function definition for a function satisfying the contract, do you know one?


pocmatos
2019-3-11 20:42:48

My worry is of course, that if there are no tests and no code using this specific case, it might have gotten broken and nobody noticed.


notjack
2019-3-11 20:44:49

I don’t know of any functions with a contract like that. I’m surprised the contract system even allows that at all.


samth
2019-3-11 20:46:13

there are a few things that use the “last argument” pattern seen there, although I don’t know if they are used with contracts anywhere


samth
2019-3-11 20:46:31
  1. one of the functions passed to chaperone-procedure works like that

samth
2019-3-11 20:46:52
  1. I think continuation prompt handlers work that way

notjack
2019-3-11 20:48:05

I would recommend against doing that in your own APIs, it’s difficult to read and use


samth
2019-3-11 20:48:44

yes, I agree with that, I hate it


pocmatos
2019-3-11 20:50:27

but what would be a function a definition satisfying such contract? (define (f n1 s1 s2 n2) ...) doesn’t satisfy and (define (f n1 . s n2) ...) is not valid. I am confused!


lexi.lambda
2019-3-11 20:51:07

You’d declare the function (define (f i . args) ....) and split args by hand. Or use define/match or something.


pocmatos
2019-3-11 20:51:43

woot? that’s ridiculous…


pocmatos
2019-3-11 20:52:07

ahhhhhhh, now I understand. ok.


pocmatos
2019-3-11 20:53:08

basically there’s no function definition syntax matching the contract syntax. But since the checking it’s done at runtime, it doesn’t matter. ugh, ugly.


pocmatos
2019-3-11 20:53:16

thanks @lexi.lambda


lexi.lambda
2019-3-11 20:54:15

Right. Racket’s define form can’t pull apart that particular argument list for you in the way you’d like, but ultimately, it’s still just a function that takes two or more arguments.


notjack
2019-3-11 20:54:51

@pocmatos fyi, all of a contract’s checks on the “shape” of the arguments a function accepts are done at runtime. The contract has no way of knowing how you wrote the define clause for the function it’s attached to.


notjack
2019-3-11 20:55:31

but the simpler cases usually just use procedure-arity and procedure-keywords


notjack
2019-3-11 20:55:58

(so it’s a single check at the time the contract is attached to the function rather than a check every time the function is called)


pocmatos
2019-3-11 20:56:13

right, i know. but my brain still tends to pattern match the contract using -> with the function definition.


notjack
2019-3-11 20:56:28

which is probably a good thing to do and a habit that the contract APIs should encourage


pocmatos
2019-3-11 20:57:09

i think i need to add an example to the docs so nobody is again made feel stupid by this particular syntax. :slightly_smiling_face:


notjack
2019-3-11 20:57:20

I think that’s a wonderful idea


notjack
2019-3-11 20:59:24

as an aside, I would really like it if ellipses were supported in define and #%app statements so I could write this: (define (my+ xs ...) (+ xs ...))


pocmatos
2019-3-11 21:10:07

actually i wonder if it makes sense to put a code example in the reference guide (https://docs.racket-lang.org/reference/function-contracts.html) given there are no code examples there. It would make more sense in the guide but the guide doesn’t mention this syntax (probably on purpose)…


samth
2019-3-11 21:14:55

more examples everywhere are good


chris613
2019-3-11 21:23:30

hi all


chris613
2019-3-11 21:23:47

is anyone about that might be able to help me out with some datalog ??


notjack
2019-3-11 21:24:06

sure!


chris613
2019-3-11 21:24:32

really strugling to understand how to impliment a rule that says “X is in set A if X is part of set B but not part of set C”


samth
2019-3-11 21:25:54

I think the datalog language doesn’t provide negation


chris613
2019-3-11 21:26:48

ahhhh


chris613
2019-3-11 21:26:59

can i do it in the racket interop mode ??


chris613
2019-3-11 21:27:16

(datalog family (? (add1 X :- 2))) <— dont understand this one :wink:


chris613
2019-3-11 21:27:34

but i can see its using “normal” racket functions add1 ?


notjack
2019-3-11 21:27:44

part of datalog’s design is to avoid negation so that it can provide various correctness and performance guarantees


samth
2019-3-11 21:27:46

no, it’s a fairly fundamental limitation of how datalog works


chris613
2019-3-11 21:27:57

hmmmm


chris613
2019-3-11 21:28:09

so is there annother way i should be thinking about the problem ?


notjack
2019-3-11 21:28:24

I think so


notjack
2019-3-11 21:28:35

What sort of rules are you making?


chris613
2019-3-11 21:28:40

i want to be able to model statments & validations and then query for things that are unvalidated


chris613
2019-3-11 21:28:59

(datalog blah (! (product)) (! (cost product 300)) (! (meets-need product "respond to rfis")) (! (average-salary sales 10000)) (! (statement "The target consumers are profesionals who's responsibilities include responding to RFI/RFP's.")) (! (responsibility sales "respond to rfis")) (! (responsibility presales "respond to rfis")) (! (statement sales "do not want to maintain a database")) (! (statement sales "are willing to work within a new environment (editor)")) (! (statement managers "get in the way")) (! (validation managers "get in the way")) (! (validation sales "do not want to maintain a database")) (! (:- (customer X) (responsibility X "respond to rfis"))) (! (:- (learning C X) (statement C X) (validation C X) (customer C))))


notjack
2019-3-11 21:29:22

that could work if you model validations as rules that say “this thing is invalid when this condition holds”


notjack
2019-3-11 21:30:07

but then I think you won’t be able to query for things that are valid (disclaimer: I am not a datalog expert and have barely used it)


chris613
2019-3-11 21:30:38

hmmmm yeah i kinda wanted / need to ability to do both


notjack
2019-3-11 21:30:54

you might be able to do it by writing rules for both


chris613
2019-3-11 21:30:57

so would “upgrading” to racklog get me out of this problem ?


chris613
2019-3-11 21:32:26

i tried messing about with rack log but the complexity killed me so i went back to datalog


notjack
2019-3-11 21:32:41

I think you would be able to do this with racklog, yeah. I’m not sure whether it would be easier to use racklog or to use datalog in a restrained way (meaning, write both “isvalid” and “isinvalid” rules for each of your validation conditions)


chris613
2019-3-11 21:33:08

i was just thinking about ” restrained way ”


chris613
2019-3-11 21:33:38

would it be possible to write a third rul to ensure each statement has either one or the other valid / invalid


chris613
2019-3-11 21:34:09

hmmmm


notjack
2019-3-11 21:35:16

I don’t know but I suspect not.


chris613
2019-3-11 21:41:30

hmmmm okies thanks a ton @notjack :slightly_smiling_face:


notjack
2019-3-11 21:41:50

happy to help :simple_smile:


plragde
2019-3-12 06:39:02

I just meant systems handling formal proof, such as Coq or Agda.