Re: [racket-users] Basic audio files' manipulation

2017-04-21 Thread 'John Clements' via Racket Users

> On Apr 21, 2017, at 18:34, Cleverson Casarin Uliana  
> wrote:
> 
> Hello, I need playing/stopping a given audio file (may be wav, ogg, etc.), 
> checking whether the sound is still playing, and stop it/start a new sound 
> upon a key press. Is there support for it, prefferably using the OS native 
> resources? In case there are only bindings to external libs, what's the more 
> responsive and/or the easiest just for such basics?

I wish I had a nicer answer for you. Here’s the state of the world, as far as 
I’m aware of it:

1) Racket has built-in support for playing sound files. This function is called 
play-sound, and you can read the docs for it.

2) Jay McCarthy’s openal package (installable using ‘raco pkg install openal’) 
provides FFI bindings to OpenAL, which does almost exactly what you want. 
AFAICT, it’s not currently documented.

3) It is possible to do what you want using  (my) rsound package (installable 
using ‘raco pkg install rsound’). It can do what you want, but it has a few 
major drawbacks. Let me enumerate them.

a) It has built-in support for reading .wav files, that’s all.
b) If you want to be able to stop a sound, you’ll want to put it on its own 
stream, so that you can just set its volume to zero. It wouldn’t be hard to 
implement individual sound stopping, but it’s not currently documented.

Well, those are probably the two biggest :).

In case you’re not already aware of this, you can read more information about 
the packages available for Racket at 

https://pkgs.racket-lang.org/

John Clements



-- 
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] Basic audio files' manipulation

2017-04-21 Thread Cleverson Casarin Uliana
Hello, I need playing/stopping a given audio file (may be wav, ogg, 
etc.), checking whether the sound is still playing, and stop it/start a 
new sound upon a key press. Is there support for it, prefferably using 
the OS native resources? In case there are only bindings to external 
libs, what's the more responsive and/or the easiest just for such basics?


Thank you,
Cleverson

--
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] literals vs datum-literals in syntax-parse

2017-04-21 Thread Phil Nguyen
On Tuesday, January 10, 2017 at 4:34:41 PM UTC-5, Alexis King wrote:
> Basically, the difference is as follows: #:literals compares
> identifiers using free-identifier=?, but #:datum-literals compares
> them by using syntax-e and eq?.
> 
> You can observe the difference using two extremely simple macros
> that only differ in their use of #:literals or #:datum-literals:
> 
>   (define-syntax lit
> (syntax-parser
>   #:literals [add1]
>   [(_ add1) #'"add1"]
>   [(_ _)#'"something else"]))
> 
>   (define-syntax dat
> (syntax-parser
>   #:datum-literals [add1]
>   [(_ add1) #'"add1"]
>   [(_ _)#'"something else"]))
> 
> Observe the behavior of the `lit` macro:
> 
>   > (lit add1)
>   "add1"
>   > (let ([add1 #f])
>   (lit add1))
>   "something else"
>   > (require (rename-in racket/base [add1 my-add1]))
>   > (lit my-add1)
>   "add1"
> 
> Contrast the results with the same examples using the `dat` macro
> instead:
> 
>   > (dat add1)
>   "add1"
>   > (let ([add1 #f])
>   (dat add1))
>   "add1"
>   > (require (rename-in racket/base [add1 my-add1]))
>   > (dat my-add1)
>   "something else"
> 
> By “recognize symbolically”, it means that #:datum-literals looks
> at the name of the symbol and nothing else. In contrast, #:literals
> is more advanced, since it looks for an identifier with the same
> binding as the one specified.
> 
> In my opinion, when in doubt, prefer #:literals.
> 
> > On Jan 10, 2017, at 11:58 AM, Deren Dohoda
> > wrote:
> > 
> > I am still making most macros using syntax-rules and syntax-case
> > because when I happened to learn macros these were the paths of
> > least resistance. Every once in a while I try to learn a little
> > more of syntax-parse since the few times I've tried it I really
> > liked it.
> > 
> > It appears that, in general, syntax-rules and syntax-case use what
> > syntax-parse considers "datum-literals", which the docs say are
> > recognized "symbolically" versus actual literals which are recognized
> > "by binding." The example in the documents for some reason clarifies
> > nothing since both expressions are the same and give the same output,
> > making this a distinction without an obvious difference.
> > 
> > Can someone explain the intention behind #:literals as opposed to
> > #:datum-literals? In what cases should I consider #:literals? Why
> > would I want to avoid #:datum-literals, or vice versa?
> > 
> > Thanks,
> > Deren

I have a related question: How does #:literals differ from ~literal in the 
left-hand side of syntax-parse? I used to think they were the same but it seems 
that changing from one to another altered my program's behavior...

-- 
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] Is this a closure?

2017-04-21 Thread David Storrs
On Thu, Apr 20, 2017 at 10:04 PM, Lawrence Bottorff 
wrote:

> Looking at HTDP-1 (http://htdp.org/2003-09-26/Bo
> ok/curriculum-Z-H-25.html#node_chap_19), I see this:
>
> (define (filter predicate alon)
>   (cond
>[(empty? alon) empty]
>[else (cond
>   [(predicate (first alon))
>(cons (first alon)
>  (filter predicate (rest alon)))]
>   [else
>(filter predicate (rest alon))])]))
>
> Then to find if a member of a list l is below a number i
>
> (define (below i l)
>   (local ((define (below-i x)
> (> i x)))
> (filter below-i l)))
>
> As the proverbial beginner -- who doesn't totally understand closures --
> this looks like a use of the closure idea. Right? The i is "magically"
> known in `filter`, which seems pretty closure-ish to me. Or am I totally
> wrong?
>
> LB
>

Yep, you nailed it.

To expand a bit, and please forgive me if this is stuff you already know:

Lexical Scope:
Different variables are accessible at different parts of your program; the
term for this is 'scope'.  There are a couple of kinds of scope but the
easiest is lexical scope, which is based on the written structure of the
program -- things at a deeper level of nesting are at a deeper scope.

Closure:
When a function is created it 'closes over' the currently visible scope.
(Hence the term, 'closure'.)  That means that it has access to the
variables that were defined at the time the closure was created, even if
those variable go out of scope and are no longer directly usable by the
rest of the program.

NB:
Note that *variables* are not the same as *values*.  A variable, e.g. 'x',
is a container for a value, e.g. 7.  There can be multiple variables named
x at any given time, all of them holding different values.  That means that
the closure may see a different 'x' than the program immediately around the
closure.  Those two variables might happen to have the same value but
probably do not.

Racket tends to say 'identifier' instead of 'variable' and calls it
'binding' a value instead of 'assigning' a value, but the concepts are
close enough for government work and if you're new to Racket then you are
likely to find the other terms more familiar.

Here's some example code that will hopefully make it all clear.  Try to
predict what the output will be before you run it.

#lang racket

;'println' et al don't play nicely with printing multiple
;arguments at once, so create a convenience function that does.
(define (say . args)
  (println (apply ~a args)))


;;The actual interesting part of the program starts here.

(define x 'x)
(say "first print: " x)

; At this point remember that we are defining a function, not running it
(define (baz)
  (define w 'w)
  (say "top of baz, w: " w) ; "2: w"

  (define (foo)
(define y 'y)
(say "top of foo, w: " w)
(say "top of foo, x: " x)
(say "top of foo, y: " y)

;Return a closure.  This closure will have access to the
;scope of foo (including the variable y) even when the
;point of execution is no longer inside foo and y is
;therefore not available.
(lambda () (say "thunk inside of foo, y: " y))
)
  (say "after foo")
  ;The variable y that was defined in foo is not visible outside
  ;of foo.  If you try to print it you will be unable to execute
  ;this file because the Racket compiler won't know what to do
  ;with the unbound variable y.
  ; (say "This won't work: " y) ; BOOM!

  (define (bar)
(define z 'z)
(say "top of bar, w: " w)
(say "top of bar, x: " x)
(say "top of bar, z: " z)

;Return a closure, as above.
(lambda () (say "thunk returned from bar, z: " z))
)
  (say "after bar")
  (say "inside baz, after declaration of foo and bar, x: " x) ; prints 'x
  (say "inside baz, after declaration of foo and bar, w: " w) ; prints 'w
  (set! x 'new-x)
  (say "inside baz, after set! x, x: " x) ; prints 'new-x because we
changed the value of x with set!
  (say "inside baz, after set! x, w: " w) ; still prints 'w

  ;Execute the foo function.  The 'say' inside of foo will print
  ;'new-x because when foo was defined it closed over the
  ;original variable x and we have now set!'d the value of the
  ;original x.  foo returns a thunk, which is what the say
  ;itself will print.
  (say "inside baz, after set! x, (foo) returns a thunk: " (foo))

  ; Execute the thunk that is returned by foo.
  (say "inside baz, after set! x, result of thunk returned by (foo): "
((foo)))


  ; Create a new variable named w with the same value as the
  ; existing w.  This is called "shadowing" a variable -- it's
  ; basically a way to take a temporary copy that exists only within
  ; the scope of the 'let'.   The copy is the 'local version'.
  (let ((w w))
(say "inside 'let', local w: " w) ; prints 'w, the variable of the
local version of w which has the same value as the original w
(set! w 'new-w) ; This affects the l

[racket-users] Cut/copy/paste buggy in DrRacket 6.8 (on my dual boot system)

2017-04-21 Thread Chris Klopfenstein
It seems that sometimes when pasting the clipboard in DrRacket (version 6.8), 
it also gets pasted into another (wrong) place. It is very annoying.

It also *seems* to occur when doing cut/paste in a different app (with DrRacket 
open).

I've experienced this in both Ubuntu (16.10 and 17.04) and Win10.

-- 
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.