[racket-users] Questions on HtDP 2e, Ex. 356

2017-07-12 Thread Ben Morin
I've been working my way through HtDP on and off over the past several months. 
I've generally been able to figure it out on my own (even if it takes awhile). 
However, Intertwined Data has given me a couple problems that I just can't seem 
to wrap my head around.

The major one is 21.3 "Interpreting Functions."
http://www.ccs.neu.edu/home/matthias/HtDP2e/Draft/part_four.html#%28counter._%28exercise._ex~3absl-one-def%29%29

Exercise 356 asks to extend the data definition of

; A BSL-var-expr is one of: 
; – Number
; – Symbol 
; – (make-add BSL-var-expr BSL-var-expr)
; – (make-mul BSL-var-expr BSL-var-expr)

to "include application of a programmer-defined function," which is a function 
name and expression, My first thought was something in line with the rest of 
the chapter:

(make-func [name expr])

But looking at examples like (k (+ 1 1)) makes it seem like the data definition 
should just incorporate a name and an argument. Where does the function's body 
come into play?

Exercise 357 then asks to create a function with the following parameters: 
- a BSL-Func-Expr, would this be just (k (+ 1 1))?
- the function name, k?
- the function parameters, (+ 1 1) is the argument?
- the function body, ... (+ 1 1)?

How can a user-defined function like "k" be evaluated if only its argument is 
known?

I feel like I read this, understand the words, but can't comprehend the 
sentences.


Thanks in advance

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Questions on HtDP 2e, Ex. 356

2017-07-12 Thread Jens Axel Søgaard
Hi Ben,

Adding syntax for both applications, user defined functions and adding
evaluation of these in the same execise, is a bit much.
It is therefore split up into exercise 356, 357, 358 and 359.

Exercise 356 is only about extending the data definition such that
applications can be represented.
In excercise 357 eval-definition1 receives as one of its argument the
function (including the body) of the user defined function.

/Jens Axel


2017-07-12 15:41 GMT+02:00 Ben Morin :

> I've been working my way through HtDP on and off over the past several
> months. I've generally been able to figure it out on my own (even if it
> takes awhile). However, Intertwined Data has given me a couple problems
> that I just can't seem to wrap my head around.
>
> The major one is 21.3 "Interpreting Functions."
> http://www.ccs.neu.edu/home/matthias/HtDP2e/Draft/part_
> four.html#%28counter._%28exercise._ex~3absl-one-def%29%29
>
> Exercise 356 asks to extend the data definition of
>
> ; A BSL-var-expr is one of:
> ; – Number
> ; – Symbol
> ; – (make-add BSL-var-expr BSL-var-expr)
> ; – (make-mul BSL-var-expr BSL-var-expr)
>
> to "include application of a programmer-defined function," which is a
> function name and expression, My first thought was something in line with
> the rest of the chapter:
>
> (make-func [name expr])
>
> But looking at examples like (k (+ 1 1)) makes it seem like the data
> definition should just incorporate a name and an argument. Where does the
> function's body come into play?
>
> Exercise 357 then asks to create a function with the following parameters:
> - a BSL-Func-Expr, would this be just (k (+ 1 1))?
> - the function name, k?
> - the function parameters, (+ 1 1) is the argument?
> - the function body, ... (+ 1 1)?
>
> How can a user-defined function like "k" be evaluated if only its argument
> is known?
>
> I feel like I read this, understand the words, but can't comprehend the
> sentences.
>
>
> Thanks in advance
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-- 
Jens Axel Søgaard

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Racket crashes when using gir module to search for libnice

2017-07-12 Thread David Storrs
I'm experimenting with FFI so that we can use libnice inside our Racket
code.  I found the gir module (
https://docs.racket-lang.org/gir/#%28def._%28%28lib._gir%2Fmain..rkt%29._connect%29%29)
which purports to simplify this project.  Using it with the wrong string
causes it to crash; based on the call stack it looks to me like the module
is with the gir module itself but I am reporting it here because I wasn't
certain it was gir as opposed to Racket / the underlying C libs and,
possibly more importantly:

Has anyone needed to use libnice before and, if so, do you have any tips?
More generally, is anyone experienced with FFI programming and willing to
answer questions about how to identify the available symbols?


Going back to the crash:

;;  test.rkt contains:
#lang racket
(require gir)
(gi-ffi "Nice")

I tried the following test from the command line:
   $ racket test.rkt

I immediately get a dialog saying "racket quit unexpectedly" and the
following message on the command line:

When running in Emacs shell-mode:

(process:53640): GLib-WARNING **: GError set over the top of a previous
GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL
before it's set.
The overwriting error message was: Typelib file for namespace 'Nice' (any
version) not found
Segmentation fault: 11

When running directly at the bash shell:
(process:53737): GLib-WARNING **: GError set over the top of a previous
GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL
before it's set.
The overwriting error message was: Typelib file for namespace 'Nice' (any
version) not found
GError: #f:  (code 1)
  context...:
   /Users/dstorrs/Library/Racket/6.6/pkgs/gir/gir/glib.rkt:30:0:
raise-g-error
   /Users/dstorrs/Library/Racket/6.6/pkgs/gir/gir/main.rkt:34:0: gi-ffi

/Applications/Racket_v6.6/collects/racket/contract/private/arrow-val-first.rkt:306:25
   /Users/dstorrs/cancer/component_testing/test.rkt: [running body]

The full details of the crash as per OSX's report are below.

Full details:
OSX 10.11.6
Macbook Pro
16G RAM
Racket 6.6
Running inside GNU Emacs 25.1.1 the first time, directly at the bash shell
the second


Apple's crash report:

Process:   racket [53622]
Path:  /Applications/Racket_v6.6/*/racket
Identifier:racket
Version:   ???
Code Type: X86-64 (Native)
Parent Process:bash [3899]
Responsible:   Terminal [457]
User ID:   501

Date/Time: 2017-07-12 12:34:54.011 -0400
OS Version:Mac OS X 10.11.6 (15G1510)
Report Version:11
Anonymous UUID:E5541413-15ED-CCC3-A512-BE7289F609E8

Sleep/Wake UUID:   31BDEF11-30FB-45C8-9494-DE27A0A69143

Time Awake Since Boot: 230 seconds
Time Since Wake:   4900 seconds

System Integrity Protection: enabled

Crashed Thread:0  Dispatch queue: com.apple.main-thread

Exception Type:EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:   KERN_INVALID_ADDRESS at 0x0203

VM Regions Near 0x203:
-->
__TEXT 0001-00018000 [   32K]
r-x/rwx SM=COW  /Applications/Racket_v6.6/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   Racket0x0001003800c9 c_to_scheme + 873
1   Racket0x000100375585 foreign_ptr_ref +
1461
2   ???   0x0001015cc13e 0 + 4317823294
3   ???   0x0001015d041b 0 + 4317840411
4   ???   0x0001015ce66d 0 + 4317832813
5   Racket0x00010006f875 scheme_do_eval +
13381
6   Racket0x0001000732c1
apply_values_execute + 225
7   Racket0x00010006e5bf scheme_do_eval +
8591
8   Racket0x0001001c6f2d body_one_expr + 173
9   Racket0x00010006d31a scheme_do_eval +
3818
10  Racket0x0001000a767f
scheme_finish_apply_for_prompt + 639
11  Racket0x0001000a7a00
scheme_apply_for_prompt + 112
12  Racket0x000100097244 call_with_prompt +
2532
13  Racket0x00010006f8fc scheme_do_eval +
13516
14  Racket0x0001000a83de
_scheme_call_with_prompt_multi + 542
15  Racket0x0001001c6b0c
scheme_module_run_finish + 1276
16  ???   0x0001015cc92d 0 + 4317825325
17  Racket0x00010019884c
scheme_module_run_start + 156
18  Racket0x0001001e2c18 eval_module_body +
216
19  Racket0x0001001e30b1 do_start_module +
273
20  Racket0x0001001bbfa3 start_module + 3779
21  Racket  

Re: [racket-users] Questions on HtDP 2e, Ex. 356

2017-07-12 Thread Ben Morin
Hi Jens

Thanks for the reply.

I was working through it with some free time today, and I think my data 
definition works. The other big problem I was having was the body for the 
user-defined function. As you said, ex 356 isn't concerned about that aspect. 
This is what was/is throwing me off. My assumption is now that I would define 
the body of an arbitrary function in the arguments of eval-definition1.

For instance:

(eval-definition1 '(by-five (make-add 1 1)) 'by-five 'p (make-mul 5 'p))

The first arg being the expression to evaluate.
Second is the function name being evaluated for.
Third being 'by-five's parameter.
Fourth being the actual body of 'by-five.

The result of eval-definition1 then being 10.

I hope this is heading in the right direction.

-- 
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.
For more options, visit https://groups.google.com/d/optout.