Re: [racket-users] Werid contract violation blame erros

2021-04-09 Thread epi via Racket Users
Thank you, Robby,

This clarifies it a little bit. So far I've avoided reading about the racket 
module system in details, but I think now is as good time as ever.
April 7, 2021 10:40 PM, "Robby Findler" mailto:ro...@cs.northwestern.edu?to=%22Robby%20Findler%22%20)>
 wrote:
The short answer: you probably should use (provide (contract-out)) instead 
of define/contract.

The slightly longer answer: when you write a contract, you are not just 
describing what the legal inputs and outputs are, you are also establishing a 
*boundary* between two regions of code. In the case of define/contract, you are 
establishing a boundary between the function (here: f) and the module that it 
contains (here the file "a.rkt"). In the case of (provide (contract-out ...)) 
the boundary is between a.rkt and b.rkt.

The slightly uncomfortable answer: it is my (not completely solid yet) opinion 
that the boundary that is drawn for define/contract is perhaps not the right / 
best one. In a theoretical/mathematical sense it is a completely fine and 
completely defensible one. But it trips people up sometimes. (There are 
examples others have posted in the past that are perhaps even stranger than 
yours but boil down to the same specific design choice for define/contract.)

Robby
On Wed, Apr 7, 2021 at 2:10 PM epi via Racket Users 
mailto:racket-users@googlegroups.com)> wrote: 
Hello Racket users,

I am trying to understand a contract violation message that I am getting.
Here is the file a.rkt:

#lang racket
(provide f)
(define/contract (f a)
(-> boolean? any/c)
'())

and this is b.rkt:

#lang racket
(require "a.rkt")
(f 3)
I would expect that the caller is blamed for the contract violation, but the 
error message that I get is as follows:
f: contract violation
expected: boolean?
given: 3
in: the 1st argument of
(-> boolean? any/c)
contract from: (function f)
blaming: /home/epi/snippets/a.rkt
(assuming the contract is correct)
at: /home/epi/snippets/a.rkt:3.18
context...:
/usr/share/racket/collects/racket/contract/private/blame.rkt:347:0: 
raise-blame-error
/usr/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:379:33
body of "/home/dan/snippets/blameme.rkt"

So, I am a bit surprised that the error message blames the file a.rkt.
What am I missing here?

--
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com 
(mailto:racket-users%2bunsubscr...@googlegroups.com).
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/149cfc632cd666ff1a92177dce90296b%40disroot.org
 
(https://groups.google.com/d/msgid/racket-users/149cfc632cd666ff1a92177dce90296b%40disroot.org).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/78a0d4875c1fa7ac222a938c3f061588%40disroot.org.


[racket-users] Werid contract violation blame erros

2021-04-07 Thread epi via Racket Users
Hello Racket users,

I am trying to understand a contract violation message that I am getting.
Here is the file a.rkt:

#lang racket
(provide f)
(define/contract (f a)
  (-> boolean? any/c)
  '())

and this is b.rkt:

#lang racket
(require "a.rkt")
(f 3)


I would expect that the caller is blamed for the contract violation, but the 
error message that I get is as follows:


f: contract violation
  expected: boolean?
  given: 3
  in: the 1st argument of
  (-> boolean? any/c)
  contract from: (function f)
  blaming: /home/epi/snippets/a.rkt
   (assuming the contract is correct)
  at: /home/epi/snippets/a.rkt:3.18
  context...:
   /usr/share/racket/collects/racket/contract/private/blame.rkt:347:0: 
raise-blame-error
   
/usr/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:379:33
   body of "/home/dan/snippets/blameme.rkt"

So, I am a bit surprised that the error message blames the file a.rkt.
What am I missing here?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/149cfc632cd666ff1a92177dce90296b%40disroot.org.


Re: [racket-users] executables

2020-12-04 Thread epi via Racket Users
Hi George,
> [For those about to object: yes, Scheme has a formal denotational definition 
> in contrast to the many languages that are operationally defined by 
> (relatively) informal description of behavior combined with a "reference" 
> implementation. Consider that Scheme's denotational spec is describing the 
> behavior of an abstract machine, and that Scheme implementations are 
> realizations of the machine.]

I was very surprised to learn about this, I always assumed Scheme was 
"officially" defined with operational semantics.
But you are right, the r7rs small contains the description of the denotational 
semantics.
Although the domains are not defined excplicitly.
Cheers,
Eugen.
November 25, 2020 6:26 AM, "George Neuner" mailto:gneun...@comcast.net?to=%22George%20Neuner%22%20)>
 wrote:
On 11/24/2020 7:34 PM, Tim Meehan wrote:Some Schemes allow you to compile to a 
(self-hosting?) executable (Chicken {via C}, Chez, Racket, others?). Some do 
not (Guile, others?), but compile to bytecode.Why would a group of developers 
choose one over the other? Or is the end result not that different in either 
case?
The reason for creating stand-alone executables is to be able to run programs 
in environments where the language tools are not, or cannot be, installed. For 
security reasons, many companies do not permit installing programming tools.

However, creating stand-alone executables is rather unrelated to what the 
compiler produces. There are a number of language implementations - Racket 
included - which can embed their bytecode (as static data) into a native 
"runtime" program which executes it.
 Is there a book/paper that I might read on this?
Unfortunately, language implementation is a very large subject area. If you 
want to understand why things are being done a certain way, you need to 
understand the ways that they *could be* done and what trade-offs are involved 
in using various methods.

Little understood fact: all languages actually are defined by a *virtual* 
abstract machine. This is the reason that languages can be implemented on many 
different real-world CPUs: it is the abstract machine that defines the 
language's behavior, and it is the abstract machine - not some CPU - that is 
the *real* compilation target.
[For those about to object: yes, Scheme has a formal denotational definition in 
contrast to the many languages that are operationally defined by (relatively) 
informal description of behavior combined with a "reference" implementation. 
Consider that Scheme's denotational spec is describing the behavior of an 
abstract machine, and that Scheme implementations are realizations of the 
machine.]

To get a sense of what is going on under the hood, you need to learn a bit 
about hardware, and a lot about compilers and interpreters. Particular language 
features often can be implemented in multiple ways, and the choices made for 
various features often affect how harmoniously they can coexist.

If you really are serious about learning this stuff, I'm sure we can keep you 
busy reading for a while.
 Cheers,Tim
George

--
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com 
(mailto:racket-users+unsubscr...@googlegroups.com).
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/8a2d8868-41b7-7b3c-eba2-2cf0517032a8%40comcast.net
 
(https://groups.google.com/d/msgid/racket-users/8a2d8868-41b7-7b3c-eba2-2cf0517032a8%40comcast.net?utm_medium=email&utm_source=footer).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/8d711e7f3a11d3ce891264db447c439f%40disroot.org.


Re: [racket-users] Re: Working with JSON using Typed Racket

2020-03-31 Thread epi
Thanks Wesley and Matthias! Very helpful advice.

March 31, 2020 2:40 AM, "Wesley Bitomski" mailto:wesley.bitom...@gmail.com?to=%22Wesley%20Bitomski%22%20)>
 wrote:
Hello Ed,
I generally get some mileage out of using custom predicates (those that are 
made with define-predicate) and pattern matching when tearing into JSON 
structures in Typed Racket. Occurrence typing seems to work with if, cond and 
assert, along with match's predicate matcher (? form).

So, something like this I think could less tedious to produce, and does exactly 
what your example does:
(: jsexpr->cd-users-data (JSExpr -> (Option (Listof String
(define (jsexpr->cd-users-data js)
(define-predicate names-list? (Listof String))
(match js
[(hash-table ['Type "DTHidden"]
['Data (hash-table ['Type "CDUsers"]
['Data (? names-list? users)])])
users]
[_ #false]))
I hope this is what you were looking for.
On Sunday, March 29, 2020 at 8:39:56 AM UTC-4, e...@disroot.org wrote:
 Hi everyone,

Recently I've been experimenting with Typed Racket and trying to 
gradually type my code base.
One of the functions that I need to write is to extract a list of strings from 
a JSON object, if it has following form:

{
"Type": "DTHidden",
"Data": { "Type": "CDUsers",
"Data": ["datum1", "datum2"] }
}

The way I used to structure it in Racket is to have a function 
`is-cdusers?` with the contract `jsexpr? -> boolean?`, which would check that 
the JSON object has the right shape; and a separate function `get-cdusers-data` 
with the contract `is-cdusers? -> listof string?`.

However, after playing a bit with Typed Racket I decided that it was 
necessary, according to my understanding of occurrence typing, to have a single 
function `get-cdusers-data` with the type `JSExpr -> (U False (Listof String))`.
In order to get it to work I ended up writing a long chain of conditionals:
(: get-cdusers-data (-> JSExpr (U False (Listof Any
(define (get-cdusers-data js)
(if (and (hash? js)
(equal? DTHidden (hash-ref js 'Type #f)))
(let ([js (hash-ref-def js 'Data [ann #hasheq() JSExpr])])
(if (and (hash? js)
(equal? CdUsers (hash-ref js 'Type #f)))
(let ([data (hash-ref js 'Data)])
(if (hash? data)
(let ([x (hash-ref js 'Data #f)])
(and (list? x) x))
#f))
#f))
#f))

Needless to say, this is a bit impractical and error-prone to write.
Does anyone know if there is a better approach to this?

From my experience with typed languages I would get that the most 
principle approach is to have an algebraic data type that represents all the 
underlying data structures, something like

type reply = ... | CDUsers of string list | ...

and then have a single function to converts a JSExpr into that data 
type.

I was hoping to avoid that, because I do enjoy working with the JSExpr 
type directly in Racket.

Does anyone have advice/experience with problems like this?

Best wishes,
-Ed--
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com 
(mailto:racket-users+unsubscr...@googlegroups.com).
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/f85a4a4d-0d0a-47e3-909b-2b378def368a%40googlegroups.com
 
(https://groups.google.com/d/msgid/racket-users/f85a4a4d-0d0a-47e3-909b-2b378def368a%40googlegroups.com?utm_medium=email&utm_source=footer).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/e678bbf9d87ef3c72db8ed45f9459c60%40disroot.org.


[racket-users] Working with JSON using Typed Racket

2020-03-29 Thread epi
Hi everyone,

Recently I've been experimenting with Typed Racket and trying to gradually type 
my code base.
One of the functions that I need to write is to extract a list of strings from 
a JSON object, if it has following form:

{
  "Type": "DTHidden",
  "Data": { "Type": "CDUsers",
"Data": ["datum1", "datum2"] }
}

The way I used to structure it in Racket is to have a function `is-cdusers?` 
with the contract `jsexpr? -> boolean?`, which would check that the JSON object 
has the right shape; and a separate function `get-cdusers-data` with the 
contract `is-cdusers? -> listof string?`.

However, after playing a bit with Typed Racket I decided that it was necessary, 
according to my understanding of occurrence typing, to have a single function 
`get-cdusers-data` with the type `JSExpr -> (U False (Listof String))`.
In order to get it to work I ended up writing a long chain of conditionals:


(: get-cdusers-data (-> JSExpr (U False (Listof Any
(define (get-cdusers-data js)
  (if (and (hash? js)
   (equal? DTHidden (hash-ref js 'Type #f)))
  (let ([js (hash-ref-def js 'Data [ann #hasheq() JSExpr])])
(if (and (hash? js)
 (equal? CdUsers (hash-ref js 'Type #f)))
(let ([data (hash-ref js 'Data)])
  (if (hash? data)
  (let ([x (hash-ref js 'Data #f)])
(and (list? x) x))
  #f))
#f))
  #f))

Needless to say, this is a bit impractical and error-prone to write.
Does anyone know if there is a better approach to this?

>From my experience with typed languages I would get that the most principle 
>approach is to have an algebraic data type that represents all the underlying 
>data structures, something like

type reply = ... | CDUsers of string list | ...

and then have a single function to converts a JSExpr into that data type.

I was hoping to avoid that, because I do enjoy working with the JSExpr type 
directly in Racket.

Does anyone have advice/experience with problems like this?

Best wishes,
-Ed

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/bc4f73636c65f68b7dae4959ea18dc19%40disroot.org.


Re: [racket-users] Logger shows lots of info messages about collapsible-contract-bailout and collapsible-value-bailout

2020-03-16 Thread epi
Thanks to you and Robby Findler for your quick replies!

March 14, 2020 4:17 PM, "Ben Greenman"  wrote:

>>> I don't know what triggers it and google does not return any results.
>>> Just curious, is it something I should be worried about?
>>> I am using Racket v7.5 if it helps.
> 
> Searching google for "collapsible contract" should point to these
> pages, at least:
> 
> https://docs.racket-lang.org/reference/collapsible.html
> https://users.cs.northwestern.edu/~dmf082/papers/collapsible.pdf
> 
> In short, racket/contract has two flavors for some contracts: "normal"
> and "collapsible". Those log messages appear when the library tries to
> use "collapsible" but has to fall back.
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to
> racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CAFUu9R4W8Z=7ytVL44w7zXxAiteWdxdS-FUhZTJN1LnjELiG8Q@m
> il.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/dc1fb21c0fe41e2bcb90386c0aa3109c%40disroot.org.


[racket-users] Logger shows lots of info messages about collapsible-contract-bailout and collapsible-value-bailout

2020-03-14 Thread epi
Hi everyone,

I was debugging my program using the logging facilities, and I was getting a 
lot of the following messages at level info:

 [ info] collapsible-contract-bailout: arrow: has optional args
 [ info] collapsible-contract-bailout: arrow: has keyword args
 [ info] collapsible-contract-bailout: arrow: no rngs
 [ info] collapsible-contract-bailout: arrow: no rngs
 [ info] collapsible-contract-bailout: arrow: multiple return values
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-value-bailout: arrow: can't prove single-return-value
 [ info] collapsible-contract-bailout: arrow: no rngs
 [ info] collapsible-contract-bailout: arrow: no rngs
 
I don't know what triggers it and google does not return any results.
Just curious, is it something I should be worried about?
I am using Racket v7.5 if it helps.
Best regards.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/335c16fb6d4ce69c5b03508eddfe9b7c%40disroot.org.