[racket-users] on the name of a data structure

2017-06-28 Thread Daniel Bastos
To me a binary tree can be defined like this.

;; A BinaryTree is either
;;   - false OR
;;   - (BinaryTree Anything BinaryTree BinaryTree)

I built a data structure which looked like a tree, but I think it's
different.  What should this be called?  I called it a blob since I didn't
know what it was.

;; A Blob is either
;;   - false OR
;;   - (Blob Stuff Stuff)

;; A Stuff is either
;;   - false OR
;;   - (Stuff Anything Blob Blob)

It looks like a BinaryTree.  Inside a blob there are two objects of type
Stuff each of which points to two other Blobs.  (Much like a binary tree
with left and right branches pointing each to two other binary trees.)

(*) Examples of blobs

1. FALSE

2. (BLOB (STUFF 'left FALSE) (STUFF 'right FALSE))

3. (BLOB
   (STUFF 'left (BLOB (STUFF 'x FALSE) (STUFF 'y FALSE)))
   (STUFF 'rigt (BLOB (STUFF 'a FALSE) (STUFF 'b FALSE

Thank you!

-- 
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] Proper non-tail recursion?

2017-04-28 Thread Daniel Bastos
On Fri, Apr 28, 2017 at 12:29 PM, Matthias Felleisen
 wrote:
>> On Apr 28, 2017, at 11:12 AM, Ben Greenman  
>> wrote:
>>
>> On Fri, Apr 28, 2017 at 11:08 AM, Daniel Bastos  wrote:
>> interview done with Guido van Rossum
>>
>> http://neopythonic.blogspot.com/2009/04/tail-recursion-elimination.html
>
> Guys, this conversation is really not about PITCH per se.

Thanks for pointing that out.  I failed to recognize the subject was
beyond my knowledge, so I totally misunderstood everything.  Thank
you!

-- 
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] Proper non-tail recursion?

2017-04-28 Thread Daniel Bastos
On Fri, Apr 28, 2017 at 11:19 AM, Matthias Felleisen
 wrote:
> [...] Their implementors will argue that deep recursions don’t exist or 
> shouldn’t be supported. [...]

Python's argument for not supporting tail-call optimization (if I
should call it that way after this thread) is that it makes it fail to
produce an informative ``Traceback''.   That's what I remember from an
interview done with Guido van Rossum.  (I don't recall any other
reasons.)

-- 
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-23 Thread Daniel Bastos
There's another sense of the word ``closure'' while still in the subject
of computing but which is different from what you've understood so far.
Your understanding and the sense of the word used by Matthias Felleisen
and David Storrs is that of Peter Landin in 1964.

In ``[t]he mechanical evaluation of expressions'', Peter Landin defines
``closure'' in the popular sense used in computing.  (This is the
earliest use of the word, as far as I know.)

   Also we represent the value of lambda-expression by a bundle of
   information called a "closure", comprising the lambda-expression
   and the environment relative to which it was evaluated.  We must
   therefore arrange that such a bundle is correctly interpreted
   whenever it has to be applied to some argument.  More precisely: a
   closure has

   an /environment part/ which is a list whose two items are:
   (1) an environment
   (2) an identifier or a list of identifiers,

   and a /control part/ which consists of a list whose sole item
   is [a lambda expression].

This is how most computer scientists use the word.  Mathematicians on
the other hand usually mean something else when it comes to ``closure''.
For example,

``a group is an algebraic structure consisting of a set of
elements equipped with an operation that combines any two elements
to form a third element.  The operation satisfies four conditions
called the group axioms, namely /closure/, associativity, identity
and invertibility.'' -- Wikipedia

But this more mathematical sense is quite relevant in computing.  The
best example I know is that from Harold Abelson (and Gerald Sussman) in
the Lisp Lectures of 1986.  Abelson is the one that uses the term in
this mathematical meaning, applying it to the design of functions.
Here's every mention of the word in the lectures.

   ``So I almost took it for granted when I said that cons allows you
   to put things together.  But it's very easy to not appreciate that,
   because notice, some of the things I can put together can
   themselves be pairs.  And let me introduce a word that I'll talk
   about more next time, it's one of my favorite words, called
   closure.  And by closure I mean that the means of combination in
   your system are such that when you put things together using them,
   like we make a pair, you can then put those together with the same
   means of combination.  So I can have not only a pair of numbers,
   but I can have a pair of pairs.''  -- Harold Abelson, lecture 2B
   ``Compound Data'', 1986.

Then again in the next lecture:

``And again just to remind you, there was this notion of closure.
See, closure was the thing that allowed us to start building up
complexity, that didn't trap us in pairs.  Particularly what I
mean is the things that we make, having combined things using cons
to get a pair, those things themselves can be combined using cons
to make more complicated things.  Or as a mathematician might say,
the set of data objects in List is closed under the operation of
forming pairs.  That's the thing that allows us to build
complexity.  And that seems obvious, but remember, a lot of the
things in the computer languages that people use are not closed.
So for example, forming arrays in basic and Fortran is not a
closed operation, because you can make an array of numbers or
character strings or something, but you can't make an array of
arrays.''  -- Harold Abelson, lecture 3A, ``Henderson Escher
Example'', 1986.

A few lectures later, Gerald Sussman uses the term, but in the sense of
Peter Landin.

``First of all, one thing we see, is that things become a little
simpler.  If I don't have to have the environment be the
environment of definition for procedure, the procedure need not
capture the environment at the time it's defined.  And so if we
look here at this slide, we see that the clause for a lambda
expression, which is the way a procedure is defined, does not make
up a thing which has a type closure and a attached environment
structure.  It's just the expression itself.  And we'll decompose
that some other way somewhere else.''  -- Gerald Sussman, lecture
7B, ``Metacircular Evaluator'', 1986.

And the two last appearances of the word, Abelson calls our attention to
the importance of the idea.

``The major point to notice here, and it's a major point we've
looked at before, is this idea of closure.  The things that we
build as a means of combination have the same overall structure as
the primitive things that we're combining.  So the AND of two
things when looked at from the outside has the same shape.  And
what that means is that this box here could be an AND or an OR or
a NOT or something because it has the same shape to interface to
the larger things.''

``It's the same thing that allowed us to get complexity in the
Escher picture

Re: [racket-users] beautiful-racket, contract-violation: expected: module-path? given ('planet ....)

2017-03-24 Thread Daniel Bastos
On Tue, Mar 21, 2017 at 5:28 PM, Alexis King  wrote:
> The unlib package is an old PLaneT package, so it won’t show up
> when you run `raco pkg show`. It’s a dependency of the snooze package
> (also from PLaneT), which you appear to have installed. Unfortunately,
> the unlib package appears to have bitrotted, so it won’t build on
> modern Racket (due to naming conflicts with new exports from #lang
> scheme that didn’t use to exist). I’ve actually been looking into
> bringing snooze and unlib up to date, just in the past few days,
> but unfortunately, it doesn’t seem to be trivial.
>
> Anyway, in the meantime, you should be able to uninstall snooze and
> unlib by using the `raco planet remove` command. That should get
> rid of the setup errors.

Snooze.  I remember installing that.  It looks like I removed it, but
a lot of output (with a lot of errors) came out.  See the result at
this link.

  https://hastebin.com/uwivicevem

Thank you for your attention.  Have a good weekend.

-- 
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] beautiful-racket, contract-violation: expected: module-path? given ('planet ....)

2017-03-21 Thread Daniel Bastos
On Tue, Mar 21, 2017 at 1:16 PM, John Clements
 wrote:
> It looks to me as though this error may have nothing to do with beautiful 
> racket, and that beautiful racket may have installed successfully.
>
> In particular, it looks like an error occurred while building the docs for 
> ‘unlib’, and that the ‘unlib’ library is something that you had installed 
> previously. Is this possible?

It's possible, though I don't remember installing it.  The system
seems to say it's not installed.

%raco pkg show unlib
Installation-wide:
 [none]
User-specific for installation "6.6":
 [none]
%

> MAJOR CAVEAT: I haven’t investigated carefully, and it’s possible that I’m 
> misreading this.
>
> Regardless, I would suggest that the library is probably successfully 
> installed. See if it’s working.

It is installed correctly.

%racket -l br/test
You installed beautiful-racket v1.0 correctly.

-- 
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] beautiful-racket, contract-violation: expected: module-path? given ('planet ....)

2017-03-21 Thread Daniel Bastos
This was installed via DrRacket.  The generated command line was:

  raco.exe pkg update --deps search-auto --scope user beautiful-racket

See errors below.  Thank you.

Resolving "beautiful-racket" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "beautiful-racket" via https://pkgs.racket-lang.org
Downloading repository
git://github.com/mbutterick/beautiful-racket/?path=beautiful-racket
00: Resolving "sugar" via https://download.racket-lang.org/releases/6.6/catalog/
01: Resolving "beautiful-racket-lib" via
https://download.racket-lang.org/releases/6.6/catalog/
03: Resolving "brag" via https://download.racket-lang.org/releases/6.6/catalog/
02: Resolving "beautiful-racket-demo" via
https://download.racket-lang.org/releases/6.6/catalog/
03: Resolving "brag" via https://pkgs.racket-lang.org
01: Resolving "beautiful-racket-lib" via https://pkgs.racket-lang.org
00: Resolving "sugar" via https://pkgs.racket-lang.org
02: Resolving "beautiful-racket-demo" via https://pkgs.racket-lang.org
Resolving "br-parser-tools-lib" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "br-parser-tools-lib" via https://pkgs.racket-lang.org
Downloading repository git://github.com/mbutterick/sugar
Using cached14900911921490091192188 for
git://github.com/mbutterick/beautiful-racket/?path=beautiful-racket-lib
Using cached14900911921490091192188 for
git://github.com/mbutterick/beautiful-racket/?path=beautiful-racket-demo
Downloading repository git://github.com/mbutterick/brag/?path=brag
Using cached14900912081490091208344 for
git://github.com/mbutterick/brag/?path=br-parser-tools%2Fbr-parser-tools-lib
Resolving "br-parser-tools-doc" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "br-parser-tools-doc" via https://pkgs.racket-lang.org
Using cached14900912081490091208344 for
git://github.com/mbutterick/brag/?path=br-parser-tools%2Fbr-parser-tools-doc
The following uninstalled packages were listed as dependencies
and they were automatically installed:
 dependencies of beautiful-racket:
   sugar
   beautiful-racket-lib
   beautiful-racket-demo
   brag
   br-parser-tools-lib
 dependencies of brag:
   br-parser-tools-doc
raco setup: version: 6.6
raco setup: platform: win32\x86_64 [3m]
raco setup: installation name: 6.6
raco setup: variants: 3m
raco setup: main collects: C:\Users\Daniel\emacs\Racket\collects
raco setup: collects paths:
raco setup:   C:\Users\Daniel\AppData\Roaming\Racket\6.6\collects
raco setup:   C:\Users\Daniel\emacs\Racket\collects
raco setup: main pkgs: C:\Users\Daniel\emacs\Racket\share\pkgs
raco setup: pkgs paths:
raco setup:   C:\Users\Daniel\emacs\Racket\share\pkgs
raco setup:   C:\Users\Daniel\AppData\Roaming\Racket\6.6\pkgs
raco setup: links files:
raco setup:   C:\Users\Daniel\emacs\Racket\share\links.rktd
raco setup:   C:\Users\Daniel\AppData\Roaming\Racket\6.6\links.rktd
raco setup: main docs: C:\Users\Daniel\emacs\Racket\doc
raco setup: --- updating info-domain tables ---
raco setup: updating:
C:\Users\Daniel\AppData\Roaming\Racket\6.6\share\info-cache.rktd
raco setup: --- pre-installing collections ---
raco setup: --- installing foreign libraries ---
raco setup: --- installing shared files ---
raco setup: --- compiling collections ---
raco setup: --- parallel build using 4 jobs ---
raco setup: 3 making: /beautiful-racket-demo/basic-demo
raco setup: 3 making: /beautiful-racket-demo/basic-demo-2
raco setup: 3 making: /beautiful-racket-demo/basic-demo-2a
raco setup: 3 making: /beautiful-racket-demo/basic-demo-3
raco setup: 3 making: /beautiful-racket-demo/basic-demo-nth
raco setup: 3 making: /beautiful-racket-demo/bf-demo
raco setup: 3 making: /beautiful-racket-demo/funstacker-demo
raco setup: 2 making: /beautiful-racket-demo/hdl-demo
raco setup: 2 making: /beautiful-racket-demo/hdl-tst-demo
raco setup: 1 making: /beautiful-racket-demo/jsonic-demo
raco setup: 0 making: /beautiful-racket-demo/jsonic-demo-2
raco setup: 3 making: /beautiful-racket-demo/jsonic-demo-3
raco setup: 1 making: /beautiful-racket-demo/stacker-demo
raco setup: 2 making: /beautiful-racket-demo/stackerizer-demo
raco setup: 1 making: /beautiful-racket-demo/txtadv-demo
raco setup: 1 making: /beautiful-racket-demo/wires-demo
raco setup: 2 making: /beautiful-racket-lib/br
raco setup: 0 making: /br-parser-tools-doc/br-parser-tools
raco setup: 1 making: /br-parser-tools-lib/br-parser-tools
raco setup: 3 making: /beautiful-racket-demo/jsonic-demo-3/scribblings
raco setup: 2 making: /beautiful-racket-lib/br/private
raco setup: 1 making: /br-parser-tools-lib/br-parser-tools/examples
raco setup: 3 making: /brag/brag (brag)
raco setup: 3 making: /brag/brag/cfg-parser
raco setup: 0 making: /sugar/sugar
raco setup: 1 making: /br-parser-tools-lib/br-parser-tools/private-lex
raco setup: 1 making: /br-parser-tools-lib/br-parser-tools/private-yacc
raco setup: 2 making: /beautiful-racket-lib/br/scribblings
raco setup: 0 making: /sugar/sugar/coerce
raco setup: 3 making: /brag/brag/codegen
raco setup: 3 ma

Re: [racket-users] racket-mode: OK to require Racket 6.0+?

2016-10-10 Thread Daniel Bastos
I use it.  I really like it.  Go ahead!  (And thank you!)

On Mon, Oct 10, 2016 at 3:08 PM, Greg Hendershott
 wrote:
> This is a heads-up that I want to update racket-mode for Emacs to
> require Racket 6.0 or newer.

[...]

-- 
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] pkg collections: packages installed, although setup reported errors

2016-09-24 Thread Daniel Bastos
​%raco pkg install collections
Resolving "collections" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "collections" via https://pkgs.racket-lang.org
Downloading repository git://github.com/lexi-lambda/racket-collections
The following uninstalled packages are listed as dependencies of
collections:
   curly-fn
   functional-lib
   match-plus
   static-rename
   unstable-list-lib
   functional-doc
Would you like to install these dependencies? [Y/n/a/c/?] Y
00: Resolving "curly-fn" via
https://download.racket-lang.org/releases/6.6/catalog/
01: Resolving "functional-lib" via
https://download.racket-lang.org/releases/6.6/catalog/
02: Resolving "match-plus" via
https://download.racket-lang.org/releases/6.6/catalog/
03: Resolving "static-rename" via
https://download.racket-lang.org/releases/6.6/catalog/
04: Resolving "unstable-list-lib" via
https://download.racket-lang.org/releases/6.6/catalog/
00: Resolving "curly-fn" via https://pkgs.racket-lang.org
02: Resolving "match-plus" via https://pkgs.racket-lang.org
03: Resolving "static-rename" via https://pkgs.racket-lang.org
01: Resolving "functional-lib" via https://pkgs.racket-lang.org
04: Resolving "unstable-list-lib" via https://pkgs.racket-lang.org
Resolving "functional-doc" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "functional-doc" via https://pkgs.racket-lang.org
Downloading repository git://
github.com/lexi-lambda/racket-curly-fn?path=curly-fn
Downloading repository git://
github.com/lexi-lambda/functional?path=functional-lib
Downloading repository git://github.com/lexi-lambda/racket-match-plus.git
Downloading repository git://github.com/lexi-lambda/racket-static-rename.git
Downloading repository git://github.com/racket/unstable-list-lib
Using cached14747234901474723490540 for git://
github.com/lexi-lambda/functional?path=functional-doc
The following uninstalled packages are listed as dependencies of curly-fn:
   curly-fn-doc
   curly-fn-lib
Would you like to install these dependencies? [Y/n/a/c/?] a
01: Resolving "curly-fn-doc" via
https://download.racket-lang.org/releases/6.6/catalog/
01: Resolving "curly-fn-doc" via https://pkgs.racket-lang.org
Resolving "curly-fn-lib" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "curly-fn-lib" via https://pkgs.racket-lang.org
Using cached14747234881474723488620 for git://
github.com/lexi-lambda/racket-curly-fn?path=curly-fn-doc
Using cached14747234881474723488620 for git://
github.com/lexi-lambda/racket-curly-fn?path=curly-fn-lib
The following uninstalled packages are listed as dependencies of
curly-fn-doc
and they will be installed:
   namespaced-transformer-doc
   namespaced-transformer-lib
   scribble-code-examples
01: Resolving "namespaced-transformer-doc" via
https://download.racket-lang.org/releases/6.6/catalog/
04: Resolving "namespaced-transformer-lib" via
https://download.racket-lang.org/releases/6.6/catalog/
01: Resolving "namespaced-transformer-doc" via https://pkgs.racket-lang.org
04: Resolving "namespaced-transformer-lib" via https://pkgs.racket-lang.org
Resolving "scribble-code-examples" via
https://download.racket-lang.org/releases/6.6/catalog/
Resolving "scribble-code-examples" via https://pkgs.racket-lang.org
Downloading repository git://
github.com/lexi-lambda/namespaced-transformer?path=namespaced-transformer-doc
Using cached14747235081474723508723 for git://
github.com/lexi-lambda/namespaced-transformer?path=namespaced-transformer-lib
Downloading repository git://github.com/AlexKnauth/scribble-code-examples
The following uninstalled packages were listed as dependencies
and they were installed:
 dependencies of collections:
   curly-fn
   functional-lib
   match-plus
   static-rename
   unstable-list-lib
   functional-doc
 dependencies of curly-fn:
   curly-fn-doc
   curly-fn-lib
 dependencies of curly-fn-doc:
   namespaced-transformer-doc
   namespaced-transformer-lib
   scribble-code-examples
raco setup: version: 6.6
raco setup: platform: win32\x86_64 [3m]
raco setup: installation name: 6.6
raco setup: variants: 3m
raco setup: main collects: c:\users\daniel\emacs\Racket\collects
raco setup: collects paths:
raco setup:   C:\Users\Daniel\AppData\Roaming\Racket\6.6\collects
raco setup:   c:\users\daniel\emacs\Racket\collects
raco setup: main pkgs: c:\users\daniel\emacs\Racket\share\pkgs
raco setup: pkgs paths:
raco setup:   c:\users\daniel\emacs\Racket\share\pkgs
raco setup:   C:\Users\Daniel\AppData\Roaming\Racket\6.6\pkgs
raco setup: links files:
raco setup:   c:\users\daniel\emacs\Racket\share\links.rktd
raco setup:   C:\Users\Daniel\AppData\Roaming\Racket\6.6\links.rktd
raco setup: main docs: c:\users\daniel\emacs\Racket\doc
raco setup: --- updating info-domain tables ---
raco setup: updating: c:\users\daniel\emacs\Racket\share\info-cache.rktd
raco setup: updating:
C:\Users\Daniel\AppData\Roaming\Racket\6.6\share\info-cache.rktd
raco setup: --- pre-installing collections ---
raco setup: --- installing foreign libraries ---
raco 

Re: [racket-users] Racket Shell

2016-08-24 Thread Daniel Bastos
On Sat, Aug 20, 2016 at 4:17 PM, William G Hatch  wrote:
> I'm really interested in people's thoughts about both parts and ways people
> think they could be improved.

Hi, William.  Have you looked at ESHELL to see if it has anything of interest?

%(format-time-string "%D %H:%M:%S" (seconds-to-time 1471456370))
08/17/16 14:52:50
%

%for i in (list 'a 'b 'c) {echo $i}
a
b
c
%

%for i in (list 'a 'b 'c) {echo x = $i}
("x" "=" a)
("x" "=" b)
("x" "=" c)
%

This echo is actually a Lisp function.

%which echo
eshell/echo is a compiled Lisp function in `em-basic.el'
%

%which *echo
c:/emacs/git/usr/bin/echo.exe
%

To invoke the echo program, use an asterisk:

%for i in (list 'a 'b 'c) {*echo x = $i}
x = a
x = b
x = c
%

The manual:
https://www.gnu.org/software/emacs/manual/html_node/eshell/index.html

-- 
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] Re: on updating the aws package to api version 20120810

2016-07-24 Thread Daniel Bastos
Hi, Greg.

I'm not sure how to elegantly keep it backward compatible.

The best thing I could come up with since yesterday would be to create
new functions for the new version, by adding a parameter to defraw.
(See below.)  Do you or does anyone have a good idea?

(defraw put-item "DynamoDB_20111205.")
(defraw get-item "DynamoDB_20111205.")
(defraw delete-item "DynamoDB_20111205.")
(defraw update-item "DynamoDB_20111205.")
(defraw batch-get-item "DynamoDB_20111205.")
(defraw batch-write-item "DynamoDB_20111205.")
(defraw query "DynamoDB_20111205.")
(defraw scan "DynamoDB_20111205.")
(defraw update-table "DynamoDB_20111205.")

(defraw put-item-20120810 "DynamoDB_20120810.")
(defraw get-item-20120810 "DynamoDB_20120810.")
(defraw delete-item-20120810 "DynamoDB_20120810.")
(defraw update-item-20120810 "DynamoDB_20120810.")
(defraw batch-get-item-20120810 "DynamoDB_20120810.")
(defraw batch-write-item-20120810 "DynamoDB_20120810.")
(defraw query-20120810 "DynamoDB_20120810.")
(defraw scan-20120810 "DynamoDB_20120810.")
(defraw update-table-20120810 "DynamoDB_20120810.")
(defraw create-table-20120810 "DynamoDB_20120810.")

Greg Hendershott  writes:

> Hi, Daniel.
>
> Thank you. At a quick glance updating the AWS API version seems
> reasonable, as does adding new functionality like create-table-jsexpr
> (but not breaking backward compatibility -- e.g. let's not remove
> create-table or change the endpoint default.)
>
> In any case would you mind making a pull request at
> https://github.com/greghendershott/aws please? That would be easier
> (for me, at least) to review, run tests automatically, discuss, etc.
>
>
> On Wed, Jul 20, 2016 at 6:30 PM, Daniel Bastos  wrote:
>> Thank you for writing the aws package.
>>
>> Currently, it supports the api version 20111205.  I updated dynamo.rkt
>> to use the newer api 20120810.  I updated the tests as well.  I touched
>> only dynamo.rkt.
>>
>> (*) What did I change
>>
>> My needs began with create-table because the new api version changed
>> considerably the jsexpr they accept.  So I thought it'd be wiser to
>> leave the building of the jsexpr to the user.
>>
>> Since creating a table is a bureaucratic jsexpr, I provided a function
>> to friendly create the jsexpr with the basic requirements.  If the user
>> decides to use more complex table creation, s/he can do so by augmenting
>> the result of create-table-jsexpr.
>>
>> The other changes were just due to the new string "DynamoDB_20120810."
>>
>> I didn't update the documentation as I don't know this will be welcome.
>> I don't mind doing so.  Let me know?  Thank you.
>>
>> (*) Tests
>>
>> %raco test dynamo.rkt
>> raco test: (submod "dynamo.rkt" test)
>> Table status is 'CREATING', waiting for 'ACTIVE'...
>> 6 tests passed
>> %
>>
>> (*) Patch
>>
>> --- dynamo.rkt.orig 2016-07-20 19:19:08.0 -0300
>> +++ dynamo.rkt  2016-07-20 19:26:55.0 -0300
>> @@ -14,6 +14,7 @@
>>   dynamo-region
>>   attribute-type/c
>>   create-table
>> + create-table-jsexpr
>>   delete-table
>>   describe-table
>>   list-tables
>> @@ -28,9 +29,9 @@
>>   update-table)
>>
>>  (define dynamo-endpoint
>> -  (make-parameter (endpoint "dynamodb.us-east-1.amazonaws.com" #t)))
>> +  (make-parameter (endpoint "dynamodb.us-west-2.amazonaws.com" #t)))
>>  (define dynamo-region
>> -  (make-parameter "us-east-1"))
>> +  (make-parameter "us-west-2"))
>>  (define service "dynamodb")
>>
>>  (define attribute-type/c (or/c "S" "N" "B"))
>> @@ -68,34 +69,37 @@
>>   (check-response in h)
>>   (bytes->jsexpr (read-entity/bytes in h)
>>
>> -(define/contract (create-table name
>> -   read-units
>> -   write-units
>> -   hash-key-name
>> -   hash-key-type
>> -   [range-key-name #f]
>> -   [range-key-type #f])
>> +(define/contract (create-table-jsexpr name
>> +  read-units
>> +  write-units
>> +  

[racket-users] on updating the aws package to api version 20120810

2016-07-20 Thread Daniel Bastos
Thank you for writing the aws package.

Currently, it supports the api version 20111205.  I updated dynamo.rkt
to use the newer api 20120810.  I updated the tests as well.  I touched
only dynamo.rkt.

(*) What did I change

My needs began with create-table because the new api version changed
considerably the jsexpr they accept.  So I thought it'd be wiser to
leave the building of the jsexpr to the user.

Since creating a table is a bureaucratic jsexpr, I provided a function
to friendly create the jsexpr with the basic requirements.  If the user
decides to use more complex table creation, s/he can do so by augmenting
the result of create-table-jsexpr.

The other changes were just due to the new string "DynamoDB_20120810."

I didn't update the documentation as I don't know this will be welcome.
I don't mind doing so.  Let me know?  Thank you.

(*) Tests

%raco test dynamo.rkt 
raco test: (submod "dynamo.rkt" test)
Table status is 'CREATING', waiting for 'ACTIVE'...
6 tests passed
%

(*) Patch

--- dynamo.rkt.orig 2016-07-20 19:19:08.0 -0300
+++ dynamo.rkt  2016-07-20 19:26:55.0 -0300
@@ -14,6 +14,7 @@
  dynamo-region
  attribute-type/c
  create-table
+ create-table-jsexpr
  delete-table
  describe-table
  list-tables
@@ -28,9 +29,9 @@
  update-table)
 
 (define dynamo-endpoint
-  (make-parameter (endpoint "dynamodb.us-east-1.amazonaws.com" #t)))
+  (make-parameter (endpoint "dynamodb.us-west-2.amazonaws.com" #t)))
 (define dynamo-region
-  (make-parameter "us-east-1"))
+  (make-parameter "us-west-2"))
 (define service "dynamodb")
 
 (define attribute-type/c (or/c "S" "N" "B"))
@@ -68,34 +69,37 @@
  (check-response in h)
  (bytes->jsexpr (read-entity/bytes in h)
 
-(define/contract (create-table name
-   read-units
-   write-units
-   hash-key-name
-   hash-key-type
-   [range-key-name #f]
-   [range-key-type #f])
+(define/contract (create-table-jsexpr name 
+  read-units 
+  write-units
+  hash-key-name 
+  hash-key-type 
+  [range-key-name #f] 
+  [range-key-type #f])
   ((string?
 exact-positive-integer? exact-positive-integer?
 string? attribute-type/c)
(string? attribute-type/c)
. ->* .
jsexpr?)
-  (raw (hasheq
-'TableName name
-'KeySchema (apply hasheq
-  (append
-   (list 'HashKeyElement
- (hasheq 'AttributeName hash-key-name
- 'AttributeType hash-key-type))
-   (if (and range-key-name range-key-type)
-   (list 'RangeKeyElement
- (hasheq 'AttributeName range-key-name
- 'AttributeType range-key-type))
-   '(
-'ProvisionedThroughput (hasheq 'ReadCapacityUnits read-units
-   'WriteCapacityUnits write-units))
-   "DynamoDB_20120810.CreateTable"))
+  (hasheq
+   'TableName name
+   'AttributeDefinitions (append 
+  (list (hasheq 'AttributeName hash-key-name
+'AttributeType hash-key-type))
+  (if (and range-key-name range-key-type)
+  (list (hasheq 'AttributeName range-key-name
+'AttributeType range-key-type))
+  '()))
+   'KeySchema (append
+   (list (hasheq 'AttributeName hash-key-name
+ 'KeyType "HASH"))
+   (if (and range-key-name range-key-type)
+   (list (hasheq 'AttributeName range-key-name
+ 'KeyType "RANGE"))
+   '()))
+   'ProvisionedThroughput (hasheq 'ReadCapacityUnits read-units
+  'WriteCapacityUnits write-units)))
 
 (define/contract (delete-table name)
   (string? . -> . jsexpr?)
@@ -144,6 +148,7 @@
 (defraw query)
 (defraw scan)
 (defraw update-table)
+(defraw create-table)
 
 ;;
 
@@ -154,9 +159,9 @@
 (test-case
  "dynamo"
  (define test (test/dynamo-table))
- (check-not-exn (λ () (create-table test 1 1
- "HashKey" "S"
- "RangeKey" "S")))
+ (check-not-exn (λ () (create-table (create-table-jsexpr test 1 1
+

[racket-users] on the racket web server and the configure servlet

2016-07-05 Thread Daniel Bastos
I'm investigating the Racket Web Server.  It seems to me the default
server-root-path is 

  Racket/share/pkgs/web-server-lib/web-server/default-web-root/htdocs

because I specified ``#:server-root-path "htdocs"'' and I saw the
program was missing conf/ files and it gave away this directory above.

In the directory above, I discovered configure.rkt.  Is it a servlet?
Reading it, I had the impression that I should hit

  http://127.0.0.1/configure

and I'd have a tool to configure my web server.  I haven't found any
documentation on this.  Is there any?  

I'm also interested in trying the examples in the examples/ directory.
So far I'm not able to access these resources.  

I also tried copying the default-web-root to my application's root
directory and I set #:server-root-path to my newly created root and
tried

  http://127.0.0.1/configure
  http://127.0.0.1/configure.rkt

with no success.  (I didn't get missing conf/ files anymore, but don't
know which URL I should hit, assuming there is one.)

Thank you.

-- 
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] on solving linear systems by way of determinants

2016-01-18 Thread Daniel Bastos
Dear Rackteers, I appreciate getting feedback on this small victory.  I
know so many come here asking for such things.  So let me try to offer
you something too.  How about fun with history?  Did you know that you
could solve linear systems with mere determinant computation?  I didn't!

After Gauss came along, nobody cares about it anymore.  Gaussian
Elimination[1] is so much better, faster and everything.  I even think
that mathematics can be defined as the game which Gauss always wins.

A long time ago, determinant theory was big and linear algebra was
small.  It's backwards now.

Do you know how the determinant program came about?  We solve a
2-unknown linear system by substituting y for an expression involving x
alone.  Then we solve for x.  With x now known, we solve for y.

As it turns out that this procedure can be represented in the following
way.  Consider the system

  ax + by = c
  dx + ey = f

To discover the value of x, you do the substitutions, which is the same
as computing

  x = (bf - ce) / (ae - bd)
  y = (af - cd) / (ae - bd)

You know these fractions can be expressed with determinants of 2x2
matrices.  So, for 2-unknown systems, we can express their solutions
with determinants.  You see, determinants /determine/ the value of these
unknowns.  That's where the word comes from.  (I think.  I couldn't cite
a source.  If you can, please do.)

But that's not all: this program generalizes to n-unknown systems.
Lancelot Hogben shows how, in his book ``Mathematics for the Million'',
W. W. Norton, 1968. (Chapter ``The Algebra of the Chessboard.'')

The bad news is when the system is either singular or indeterminate.  By
merely computing determinants, we can't even know which is which.  The
denominator of any unknown is zero in either case.  To find out which is
the case, we have to reduce the rows, handing the victory to Gauss, the
prince of mathematicians.

Thank you!

--8<---cut here---start->8---
#lang racket

;; A Row is a (List-of Number)
;; Examples:
;; (make-row '(1 1 1)) '(1 1 1)

(define (make-row ls)
  (cond [(empty? ls) (error 'make-row "a row cannot be empty")]
[else ls]))

;; A Matrix is either
;;  - Empty OR
;;  - (make-matrix (List-of Row))

;; Examples:
;; empty
;; (make-matrix) empty
;; (make-matrix '((1 0) (0 1))) '((1 0) (0 1))
;; (make-matrix '((1 0 0 -2) (0 1 0 -3) (0 0 1 -4))) '((1 0 0 -2) (0 1 0 -3) (0 
0 1 -4))
;; (make-matrix '((1 1 1) (1 1))) "error: rows of different lengths"

(define (make-matrix [ls-of-ls empty])
  (local [(define (same-numbers? ls-of-ls)
(cond [(or (= 0 (length ls-of-ls)) (= 1 (length ls-of-ls))) #t]
  [else (if (not (= (first ls-of-ls) (second ls-of-ls)))
#f
(same-numbers? (rest ls-of-ls)))]))]
 (cond [(empty? ls-of-ls) empty]
   [(not (same-numbers? (map length ls-of-ls)))
(error 'make-matrix "rows of matrix don't have the same 
lengths")]
   [else ls-of-ls])))

;; Matrix -> (List-of Number) OR Symbol

;; Takes a matrix representing a system of equations Ax=b and produces
;; the solution set for the system.  The vector b must be provided in
;; the matrix (as the last column.)  If the system has a non-unique
;; solution or no solution, I merely produce

;;'no-solution-or-non-unique-solution

;; because I don't know how to do better.

;; Examples:
;; (solve '((1 0 -2) (0 1 -3))) (2 3)
;; (solve '((1 0 0 2) (0 1 0 3) (0 0 1 4))) (-2 -3 -4)
;; (solve '((0 0 0 0) (0 1 0 3) (0 0 1 4))) 'no-solution-or-non-unique-solution
;; (solve '((1 0 -2) (0 x -3))) 'non-numeric-matrix

(define (solve m)
  (if (not (matrix-numbers-only? m))
  'non-numeric-matrix
  (let* ([rows (matrix-rows m)]
 [cols (matrix-cols m)]
 [Dc (determinant (matrix-erase-column m cols))])
(if (= Dc 0)
'no-solution-or-non-unique-solution
(map (lambda (i)
   (solve-for m i)) (build-list rows (lambda (t) (add1 t

;; A VariableIndex is an Index, but with a restriction.  For a matrix
;; (make-matrix '((1 0 -2) (0 1 -3))), while Index can be any of 1, 2
;; and 3, VariableIndex can only be 1 or 2.  In other words,
;; VariableIndex ranges on the unknowns of the system, not on the
;; columns of the matrix.

;; Matrix VariableIndex -> Number

;; Takes a matrix m, an index x specifying a variable to be solved for
;; and produces the value of that variable, if the system has a
;; solution.  We assume the system always has a unique solution.

;; Examples:
;; (solve-for '((1 0 -2) (0 1 -3)) 2) 3
;; (solve-for '((1 0 -2) (0 1 -3)) 1) 2
;; (solve-for '((1 0 0 -2) (0 1 0 -3) (0 0 1 -4)) 1) 2
;; (solve-for '((1 0 0 -2) (0 1 0 -3) (0 0 1 -4)) 2) 3
;; (solve-for '((1 0 0 -2) (0 1 0 -3) (0 0 1 -4)) 3) 4

;; The names Dx and Dc follow up on the notation by Lancelot Thomas
;; Hogben, exposed in ``Mathematics for the Million'', W. W. Norto

[racket-users] on "module: identifier already imported from a different source"

2015-06-30 Thread Daniel Bastos
I'm getting "module: identifier already imported from a different
source" when I require these two modules.

(require math/number-theory)
(require racket/list)

I want factorize from math/number-theory and remove-duplicates from racket/list.

I've seen old messages about this error, but they seemed involved with
the full-fledged Racket, while I'm using ISL+ in DrRacket. I decided
to try some things out of HtDP and ended up getting into this trouble.

I don't want the full-fledged Racket because I like to use
check-expect in DrRacket and I seem to get along better with the
student languages error messages.

Solutions such as (require (rename ... ) don't work for me because I'm
speaking ISL+ where my options seem to me these below. (ASL doesn't
seem to expand on it.)

  library-require = (require string)
 | (require (lib string string ...))
 | (require (planet string package))

Perhaps you could suggest me to leave the student languages sometimes
when playing with Racket by showing me how I could get some equivalent
thing to check-expect.

At some point I should move to full-fledged Racket. I suppose after
HtDP I should read another book. Perhaps Realm of Racket?

Thank you.

-- 
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] htdp/2e: exercises 336-338, feedback desired and questions

2015-04-02 Thread Daniel Bastos
​​
Exercise 336. Is (bundle "abc" 0) a proper use of the bundle function? What
does it produce? Why?


​Solution. It's not a proper use. It produces nothing. It doesn't
terminate. Because (drop ls 0)​ returns a list not smaller than ls, hence
the recursion of bundle doesn't reach the base case.

I felt like adding an error case to bundle.

; [List-of 1String] n -> [List-of String]
; produces a list of n-string from a list of 1-string

; exercise 336
; an error case, because you cannot group a nonempty list into groups of 0
(check-error (bundle (explode "mumble") 0))

(define (bundle ls n)
  (cond
[(empty? ls) empty]
[(= n 0) (error "0-bundles cannot represent a nonempty list")]
[else (cons (implode (take ls n)) (bundle (drop ls n) n))]))

End of solution.

​​
Exercise 337. Define the function list->chunks. It consumes a list l of
arbitrary data and a natural number n. The function’s result is a list of
list chunks of size n. Each chunk represents a sub-sequence of items in l.

Use list->chunks to define bundle via function composition.


​Solution. To define bundle via function composition, I used map. I don't
know if that was the desired answer. I called it bundle-string. I think
bundle-string is really partition of exercise 338, so I'm not understanding
either this last bit of 337 or the entire point of 338.

​; exercise 337
; ls n -> [List-of [List-of n-chunks]]
; produces a list of lists of chunks
; where each chunk represents a subsequence of items in ls

; boundaries
(check-expect (list->chunks empty 3) empty)
(check-expect (list->chunks empty 0) empty)

; usual case
(check-expect (list->chunks '(a b c d e f g) 2) (list '(a b) '(c d) '(e f)
'(g)))

(define (list->chunks ls n)
  (cond
[(or (= n 0) (empty? ls)) empty]
[else (cons (take ls n) (list->chunks (drop ls n) n))]))

; bundle via list->chunks
(check-expect (bundle-string (explode "mumble") 2) (bundle-string (explode
"mumble") 2))

(define (bundle-string ls n)
  (map implode (list->chunks ls n)))
​
End of solution.

Exercise 338. Define the function partition. It consumes a String s and a
natural number n. The function produces a list of string chunks of size n.

For non-empty strings s and positive natural numbers n,

(equal? (partition s n) (bundle (explode s) n))

is true. But don’t use this equality as the definition for partition; use
substring instead.

Hint Have partition produce its “natural” result for the empty string. For
the case wheren is 0, see exercise 336.

Note The partition function is somewhat closer to what a cooperative
DrRacket environment would need than bundle.


I couldn't do this exercise. I can't use that equality as the definition
for partition. I must use substring. But to me the definition of partition
is my bundle-string above, which doesn't use substring and I think I'm
missing the whole point of partition. I can't see how substring could help
me. And even if it could, I think it would be very unclear, because to me
the clearest thing is to use map, since I want to implode each chunk in the
list.

Thank you for your attention.

-- 
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] manifesto move

2015-03-30 Thread Daniel Bastos
Matthias, at least in this new address the PDF is a broken link. It
currently points to

  http://www.ccs.neu.edu/home/matthias/manifesto/manifesto.pdf

which yields a "file not found" answer upon request.

On Sat, Mar 28, 2015 at 11:03 AM, Matthias Felleisen 
wrote:

>
> Now that the scribble is mostly cleaned up, I have moved the manifesto to
> a less temporary place:
>
>  http://www.ccs.neu.edu/home/matthias/manifesto/
>
> -- Matthias

-- 
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] htdp/2e: on types and popular scripting languages

2015-01-22 Thread Daniel Bastos
Near exercise 305, HtDP/2e says that "[in] ISL+ (... and in the currently
popular scripting languages) such an informal signature with a definite
meaning is acceptable on occasion; do not use it too often, however."

It refers to this definition.

; [List-of Attribute] or [List-of Xexpr.v2] -> Boolean
; is the given value a list of attributes?
(define (list-of-attributes? x)
  (cond
[(empty? x) #true]
[else (local ((define possible-attribute (first x)))
(cons? possible-attribute))]))

Why "acceptable on occasion"? I don't get the message. What is it saying?
Thank you.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] htdp/2e: exercise 302, difficulties

2015-01-21 Thread Daniel Bastos
;Gentlemen, I'm having difficulties with X-expressions. I decided to make
up examples for each type that appears as a way to engage myself in the
business, but I fail to be sure whether my examples are correct.

; An Xexpr.v0 (short for X-expression) is
;   (cons Symbol '())
(define sv0.0 (cons 'machine empty))
(define sv0.1 (cons 'another empty))

;These v0 I'm confident.

; An Xexpr.v1 is
;   (cons Symbol [List-of Xexpr.v1])
(define sv1.0 (cons 'machine empty))
; 
;  
;  
;  
; 
(define initial (cons 'initial empty))
(define state1 (cons 'state empty))
(define state2 (cons 'state empty))
(define a-machine (cons 'machine (list initial state1 state2)))

;I made up the XML example to be able to translate it piece by piece to
make it easier. I claim now that a-machine represents the XML expression
above.

; An Xexpr.v2 is
; – (cons Symbol [List-of Xexpr.v2])
; – (cons Symbol (cons [List-of Attribute] [List-of Xexpr.v2]))

(define a-cluster (cons 'a-cluster (list a-machine a-machine)))

;Our sample data representations from above suggest this definition for
Attribute:

; An Attribute is
;   (cons Symbol (cons String '()))

(define a-name-attr (cons 'name (cons "cluster x" empty)))
(define a-named-cluster (cons 'a-named-cluster (cons (list a-name-attr)
(list a-machine a-machine

; At first at least, it's difficult to write these expressions and be sure
they conform. I'm using other definitions to write less long expressions.

; Exercise 302. Eliminate the use of List-of from the data definition
Xexpr.v2. #

; I think I don't get the spirit of this exercise. If I eliminate the use
of List-of from Xexpr.v2, how can I get lists of attributes or lists of
x-expr.v2? But see my attempt below.

; (*) Solution

; A ListOfAttributes is
;  - empty
;  - (cons Attribute ListOfAttributes)

; A ListOfXexpr.v2 is
;  - empty
;  - (cons Xexpr.v2 ListOfXexpr.v2)

; So we can express Xexpr.v2 without the List-of operator by using these
types above.

; An Xexpr.v2 is
; – (cons Symbol ListOfXexpr.v2)
; – (cons Symbol (cons ListOfAttributes ListOfXexpr.v2))

; Is this what the exercise expects? Thank you.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] htdp/2e: exercise 197, a solution, feedback welcome

2015-01-21 Thread Daniel Bastos
I had a lot of difficulties with exercise 195, 196, 197. I'm posting my
solution to exercise 197 to get a chance to get feedback. How would have
you represented the FSM from exercise 100?

;Exercise 197. Consider the following data representation for finite state
machines:
(define-struct fsm (initial transitions final))
(define-struct transition (current key next))

; An FSM.v2 is a structure:
;   (make-fsm FSM-State LOT FSM-State)
; A LOT is one of:
; – empty
; – (cons Transition.v3 LOT)
; A Transition.v3 is a structure:
;   (make-transition FSM-State KeyEvent FSM-State)

;Represent the FSM from exercise 100 in this context.
;Design the function fsm-simulate, which accepts an FSM.v2 and runs it on a
player’s key strokes. If the sequence of key strokes force the FSM.v2 to
reach a final state, fsm-simulate stops. Hint The function uses the initial
field of the given fsm structure to keep track of the current state.

;(*) Solution

(define-struct fsm (initial transitions final))
(define-struct transition (current key next))

; An FSM.v2 is a structure:
;   (make-fsm FSM-State LOT FSM-State)
; A LOT is one of:
; – empty
; – (cons Transition.v3 LOT)
; A Transition.v3 is a structure:
;   (make-transition FSM-State KeyEvent FSM-State)

; a(b|c)*d

(define AA "start, expect to see an 'a' next")
(define BC "expect to see: 'b', 'c', or 'd'")
(define DD "encountered a 'd', finished")
(define ER "error, user pressed illegal key")

(define fsm-exe100
  (make-fsm AA
(list (make-transition AA "a" BC)
  (make-transition BC "b" BC)
  (make-transition BC "c" BC)
  (make-transition BC "d" DD)
  (make-transition AA "d" DD))
DD))

; code begins

(define CANVAS (empty-scene 300 20))

(define (show-state a-fsm)
  (place-image (text (fsm-initial a-fsm) 14 "black")
   100 10 CANVAS))

; FSM -> SimulationState.v2
; match the keys pressed by a player with the given FSM
(define (fsm-simulate a-fsm)
   (big-bang a-fsm
 (to-draw show-state)
 (on-key find-next-state)
 (stop-when last-state?)))

; SimulationState.v2 -> Boolean
(define (last-state? world-fsm)
  (string=? (fsm-initial world-fsm) (fsm-final world-fsm)))

(check-expect (not (last-state? fsm-exe100)) true)

; Transition.v3 Transition.v3 -> Boolean
(define (transition=? t1 t2)
  (and
   (string=? (transition-current t1) (transition-current t2))
   (string=? (transition-key t1) (transition-key t2))
   (string=? (transition-next t1) (transition-next t2

; FSM.v2 KeyEvent -> FSM.v2
; produces the machine with the next state associated with ke
(define (find-next-state a-fsm ke)
  (make-fsm (find (fsm-transitions a-fsm) (fsm-initial a-fsm) ke)
(fsm-transitions a-fsm)
(fsm-final a-fsm)))

; [List-of transition] FSM-State KeyEvent -> FSM-State
; finds the next FSM-State in the transition where 'current' is located
(define (find ls current ke)
  (cond
[(empty? ls) (error (string-append "not found: " ke " " current))]
[else (cond
[(and (string=? current (transition-current (first ls)))
  (key=? ke (transition-key (first ls
 (transition-next (first ls))]
[else
 (find (rest ls) current ke)])]))

(check-error (find (fsm-transitions fsm-exe100) AA "b"))
(check-expect (find (fsm-transitions fsm-exe100) AA "a") BC)
(check-expect (find (fsm-transitions fsm-exe100) BC "b") BC)
(check-expect (find (fsm-transitions fsm-exe100) BC "c") BC)
(check-expect (find (fsm-transitions fsm-exe100) BC "d") DD)

(check-error (find-next-state fsm-exe100 "b"))
(check-expect (find-next-state fsm-exe100 "a") (make-fsm BC
(fsm-transitions fsm-exe100) DD))

(check-expect (find-next-state
   (find-next-state fsm-exe100 "a") "b")
  (make-fsm BC (fsm-transitions fsm-exe100) DD))

(check-expect (find-next-state
   (find-next-state
(find-next-state fsm-exe100 "a") "b") "c")
  (make-fsm BC (fsm-transitions fsm-exe100) DD))

(check-expect (find-next-state
   (find-next-state
(find-next-state
 (find-next-state fsm-exe100 "a") "b") "c") "d")
  (make-fsm DD (fsm-transitions fsm-exe100) DD))

(check-expect (find-next-state
 (find-next-state fsm-exe100 "a") "d")
  (make-fsm DD (fsm-transitions fsm-exe100) DD))

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] htdp/2e: exercise 48, drracket highlighting

2015-01-19 Thread Daniel Bastos
Exercise 48. If you copy and paste the above function definition into the
definitions area of DrRacket and click RUN, DrRacket highlights two of the
three cond lines. This coloring tells you that your test cases do not cover
all possible cases. Add enough tests to make DrRacket happy. #

This exercise confused me for a long time. But now I understand it. The
words that threw me off were "do not cover all possible cases". I thought
it referred to the cases in the cond lines. I put an else there and still
saw lines being highlighted, including the expression in the else clause. I
was then sure I didn't understanding something. (By "test cases" I thought
they were the boolean expressions in the cond lines.)

Now I get it. DrRacket highlights the sections of code for which I didn't
write tests. That's a very nice feature. I think the book mentions this
feature for the first time in exercise 48.

On the web, someone had the same interpretation[1].

[1] Source:
http://stackoverflow.com/questions/12242573/trying-to-understand-why-drracket-highlights-some-of-my-cond-clauses

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] htdp/2e: on the choice of some names

2015-01-15 Thread Daniel Bastos
(*) Curiosity

1. I wonder what BS stands for in this definition.

; A BS is one of:
; — "hello",
; — "world", or
; — pi.

Is it just a synonym for nonsense?

2. I figure "MT" means "empty" because of how it sounds. Is that it?

; an empty scene:
(define MT (empty-scene 100 100))

3. I figure "posn" comes from the word "position". Is that it?

Thank you.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] htdp: exercise 21.1.3

2014-09-25 Thread Daniel Bastos
The solution is missing, but I thought of exposing this one here so that it
gets scrutinized before sending it to Robby Findler.

;; Exercise 21.1.3. Define natural-f, which is the abstraction of the
;; following two functions:
;;
;; ;; copy : N X  ->  (listof X)
;; ;; to create a list that contains
;; ;; obj n times
;; (define (copy n obj)
;;   (cond
;; [(zero? n) empty]
;; [else (cons obj
;; (copy (sub1 n) obj))]))
;;
;; ;; n-adder : N number  ->  number
;; ;; to add n to x using
;; ;; (+ 1 ...) only
;; (define (n-adder n x)
;;   (cond
;; [(zero? n) x]
;; [else (+ 1
;;  (n-adder (sub1 n) x))]))
;;
;; Don't forget to test natural-f. Also use natural-f to define
;; n-multiplier, which consumes n and x and produces n times x with
;; additions only. Use the examples to formulate a contract.
;;
;; Hint: The two function differ more than, say, the functions sum and
;; product in exercise 21.1.2. In particular, the base case in one
;; instance is a argument of the function, where in the other it is just
;; a constant value.
;;
;; (*) Solution
;;
;; After following the design recipe for abstraction, we get natural-f as
;; shown below. To write the contract, let's first only consider copy,
;; then we consider only n-adder and then we consider both.
;;
;; ;; natural-f-copy: Nat X (X (listof X) -> (listof X)) (listof X) ->
(listof X)
;; ;; natural-f-adder: Nat number (number number -> number) number -> number
;;
;; The contract for natural-f-adder is more specific than
;; natural-f-copy. The difference between these is that in the first, two
;; different types are involved --- X and (listof X). Therefore, (listof
;; X) works as another variable, so let's call it Y in the final version.

;; natural-f: Nat X (X Y -> Y) Y -> Y
(define (natural-f n x f init)
  (cond
[(zero? n) init]
[else (f x
  (natural-f (sub1 n) x f init))]))

;; (*) Tests

;; Let's use two different types in copy, say symbol and then number.

(check-expect (copy 3 'a) '(a a a))
(check-expect (natural-f 3 'a cons empty) (copy 3 'a))

(check-expect (copy 0 'a) empty)
(check-expect (natural-f 0 'a cons empty) (copy 0 'a))

(check-expect (copy 3 1) (list 1 1 1))
(check-expect (natural-f 3 1 cons empty) (copy 3 1))

;; For n-adder, let's make sure to test different init-values.

(check-expect (n-adder 3 3.14) 6.14)
(check-expect (natural-f 3 1 + 3.14) (n-adder 3 3.14))

(check-expect (n-adder 3 1) 4)
(check-expect (natural-f 3 1 + 1) (n-adder 3 1))

(check-expect (n-adder 3 2) 5)
(check-expect (natural-f 3 1 + 2) (n-adder 3 2))

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] on reversing a list by way of sort

2014-09-15 Thread Daniel Bastos
Dear Racketeers, I was studying the exercise 20.2.4 of HtDP when I came up
with this way of reversing lists. (Every element is a least element. Or
greatest.)

(define (f x y)
  true)

(define (rev ls)
  (sort ls f))

Welcome to DrRacket, version 6.0.1 [3m].
Language: Intermediate Student; memory limit: 256 MB.
> (rev (list 1 3 4))
(list 4 3 1)
> (rev '(a b c d))
(list 'd 'c 'b 'a)
>

Now I'm feeling like an expert. (But my friends still call me Danewbie.)

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] missing solution 20.1.2 ex:syn-funcs

2014-09-15 Thread Daniel Bastos
On Mon, Sep 8, 2014 at 9:51 PM,
Matthias Felleisen  wrote:

On Sep 2, 2014, at 12:05 PM, Daniel Bastos wrote:
>
> > Exercise 20.1.2. Argue why the following sentences are legal
> > definitions:
> >
> > (define (f x) (x 10))
> >
> > (define (f x) f)
> >
> > (define (f x y) (x 'a y 'b))
> >
> > Solution. The relevant part of the grammar is the following.
> >
> >   = (define (  ...) )
> >| (define  )
> >| (define-struct  (  ...))
> >
> > (*) First definition
> >
> > The LHS is a list of , since we find f and x as members of the
> > list and they're both variables. The RHS is a list consisting of a
> >  and a .
>
> Small correction. Let's not call (x 10) a list. It's an application. '(x
> 10) would be a list and this one character is critical.
>

Indeed. Here's a full rewrite for completeness. (Thanks!)

Exercise 20.1.2. Argue why the following sentences are legal
definitions:

(define (f x) (x 10))

(define (f x) f)

(define (f x y) (x 'a y 'b))

Solution. The relevant part of the grammar is the following.

   = (define (  ...) )
| (define  )
| (define-struct  (  ...))

(*) First definition

The LHS is a list of , since we find f and x as members of the
list and they're both variables. The RHS is an application of the form
( ), which makes up an , satisfying the first form
of . In other words,

  (define ( ) (  ) ( ) =
  (define ( ) ).

Therefore it's a legal .

(*) Second definition

Same LHS as the previous, so we need only check the RHS which is a
.  is a valid form of , so we have

  (define ( ) ) =
  (define ( ) ).

Therefore it's a legal .

(*) Third definition

The LHS is (  ), while the RHS is (  
), so we have

  (define (  ) (   )) =
  (define (  ) (   )) =
  (define (  ) ).

Therefore it's a legal .

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] missing solution 20.1.1 ex:sem-funcs

2014-09-15 Thread Daniel Bastos
On Fri, Sep 12, 2014 at 6:43 PM,
Matthias Felleisen  wrote:


> On Sep 12, 2014, at 4:40 PM, Daniel Bastos  wrote:
>
> > Again, we start with (2) and apply a series of substitutions.
> >
> > (f f)
> >   = ( ) ;; since f is a 
> >   = ( ) ;; since  is a subset of 
> >
> > However, ( ) is not by definition a value. It is an
> > expression which may or may not /have/ a value. We know the
> > definition of f, however, which tells us that it behaves like
> > the identity function. So the evaluation of that ( )
> > yields a function, which is a value. We end with
> >
> >   = 
> >
> > Therefore (2) is a value
>
> Is there a difference between the statements
>
>  "Daniel is a hat."
>
> and
>
>  "Daniel has a hat."
>
> or do they really mean the same thing?
>

There's a difference.


> In this spirit, is there a difference between the statement
>
>  "(f f) is a value."
>
> and
>
>  "(f f) has a value."
>
> or do they really mean the same thing?
>

There's a difference. The analogy is good. (I do remember having read this
analogy in the book, though I can't seem to find it right now.)

Here's my final rewrite. Feel free to scrutinize it. (BTW, thanks for your
attention.)

Exercise 20.1.1. Assume the Definitions window in DrScheme contains
(define (f x) x). Identify the values among the following expressions:

 (1) (cons f empty)
 (2) (f f)
 (3) (cons f (cons 10 (cons (f 10) empty)))

Explain why they are values and why the remaining expressions are not
values.

Solution. A value is anything of the form

   =  |  |  | empty | 
  |  (names of defined functions)
  | 

where  is of the form

   = empty | (cons  ).

Now we start with (1) and apply a series of substitutions based on the
definitions we have.

(cons f empty)
  = (cons  )  ;; since f is a 
  = (cons  )  ;; since empty is a 
  = (cons  )  ;; since  is a subset of 
  =;; definition of 
  =;; definition of 

Therefore (1) is a value.

Next we consider (2). Here's a relevant part of the grammar for (2).

   = 
  | 
  | (  ...)

Start with (2)...

(f f)
  = ( ) ;; since f is a 
  = ( ) ;; since  is a subset of 

Now ( ) is not by definition a value. Expressions may have
values, but they're not values. (Daniel may have a hat, but Daniel is
not a hat.)

Therefore (2) is not a value.

Now (3).

(cons f (cons 10 (cons (f 10) empty)))
  = (cons  (cons  (cons ( ) )))

The whole expression depends on the application ( ),
which may or may not have a value. Since we know f, we know it has a value,
but it /is not/ a value.

Therefore (3) is not a value.

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] missing solution 20.1.1 ex:sem-funcs

2014-09-12 Thread Daniel Bastos
On Mon, Sep 8, 2014 at 9:51 PM,
Matthias Felleisen  wrote:

On Sep 2, 2014, at 11:45 AM, Daniel Bastos wrote:
>
> > A candidate for a solution.
> >
> > Exercise 20.1.1. Assume the Definitions window in DrScheme contains
> > (define (f x) x). Identify the values among the following expressions:
> >
> > (1) (cons f empty)
> > (2) (f f)
> > (3) (cons f (cons 10 (cons (f 10) empty)))
> >
> > Explain why they are values and why the remaining expressions are not
> > values.
> >
> > Solution. First we consider (1). Here's the relevant part of the
> > grammar.
> >
> >   = empty | (cons  )
> >
> >   =  |  |  | empty | 
> >  |  (names of defined functions)
> >  | 
> >
> > So (1) is a value because it is  of the form (cons  empty),
> > where f is  because it is a defined function.
> >
> > Let's consider (3) before (2). (3) is a list of either  or ,
> > so (3) is  as well.
>
> You checked only one half of the value-grammar for lst. Check the other
> half, too. Report back whether you want to change the answer or not. --
> Matthias
>

I want to change it completely. I'm not very sure about what's going on.
Perhaps the other half would be this: since  is a value in this
context because f is in fact a defined function, then we get (cons 
) because empty is a  too and then (cons  ) =  due
to the definition of . Since any  is a , we get a value. (Is
that what you meant with 'check the other half'?)

Here's my new complete attempt at the problem. (I ended up saying they're
all values, due to the fact that we know f and f always yields values.)

Exercise 20.1.1. Assume the Definitions window in DrScheme contains
(define (f x) x). Identify the values among the following expressions:

 (1) (cons f empty)
 (2) (f f)
 (3) (cons f (cons 10 (cons (f 10) empty)))

Explain why they are values and why the remaining expressions are not
values.

Solution. A value is anything of the form

   =  |  |  | empty | 
  |  (names of defined functions)
  | 

where  is of the form

   = empty | (cons  ).

Now we start with (1) and apply a series of substitutions based on the
definitions we have.

(cons f empty)
  = (cons  )  ;; since f is a 
  = (cons  )  ;; since empty is a 
  = (cons  )  ;; since  is a subset of 
  =;; definition of 
  =;; definition of 

Therefore (1) is a value.

Next we consider (2). Here's the relevant part of the grammar.

   = 
  | 
  | (  ...)

Again, we start with (2) and apply a series of substitutions.

(f f)
  = ( ) ;; since f is a 
  = ( ) ;; since  is a subset of 

However, ( ) is not by definition a value. It is an
expression which may or may not /have/ a value. We know the
definition of f, however, which tells us that it behaves like
the identity function. So the evaluation of that ( )
yields a function, which is a value. We end with

  = 

Therefore (2) is a value.

Now (3).

(cons f (cons 10 (cons (f 10) empty)))
  = (cons  (cons  (cons ( ) )))

Now again, the whole expressions depends on the application ( ),
which may or may not have a value. Since that is a call to f, the
identity function, we know it returns its argument, so

  = (cons  (cons  (cons  )))
  = (cons  (cons  (cons  ))) ;;  is a 
  = (cons  (cons  ))  ;; definition of 
  = (cons  (cons  ))  ;;  is a 
  = (cons  )   ;; definition of 
  = (cons  )   ;;  is a 
  = ;; definition of 
  = ;;  is a 

Therefore (3) is a value.

Thanks for your attention.

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] missing solution 20.2.4 ex:fancy-contracts-poly

2014-09-12 Thread Daniel Bastos
On Mon, Sep 8, 2014 at 9:51 PM,
Matthias Felleisen  wrote:

On Sep 4, 2014, at 12:54 PM, Daniel Bastos wrote:
>
> > A candidate for a solution. (I'm not sure I'm correct regarding the
> > function project. The description says "a lists of lists" (which I
> > translate to (listof ITEM)) and "a function from lists to Xs", so I
> > wonder if the domain of this function-argument must be (listof ITEM)
> > or it could be more general such as (listof Y). I decided to imagine
> > that the domain of the function-argument would be items of the "list
> > of lists" and so I made it into (listof ITEM).
>
>
> In this context ITEM and X and Y are variables (placeholders) that stand
> for sets (classes) of data.
>
> In the following I have translated the purpose statements for these
> functions into prototype calls:
>
> > sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM)
>
>
> (sort a-list-of-Xs compare-Xs) : a-list-of-Xs
>   (same Xs indeed, but rearranged)
>
> > map: ((listof ITEM) -> X) (listof ITEM) -> (listof X)
>
> (map a-function-from-item-on-list-to-X a-list-of-ITEMs) : a-list-of-Xs
>
>
>
> > project: (listof (listof ITEM)) ((listof ITEM) -> (listof X)) -> (listof
> X)
>
> (project a-list-of-list-of-ITEMs a-function-from-list-of-ITEMs-to-X) :
> a-list-of-Xs
>
> > (*) Comparison with exercise 20.2.2
>
> Abstraction works by taking two concrete examples and replacing matching
> concrete things with variables.
>
> 20.2.2 asks you to come up with contracts for functions that work on one
> basic kind of data. Use a distinct kind and then apply the abstraction
> design recipe. You will find that at least one of the above is wrong.


Indeed. (That was map.) Thank you.

(*) Candidate for solution for exercise 20.2.4

Our approach will be to take two concrete examples and replace matching
concrete things with variables.

(-) Sort

sort1: (listof number) (number number -> boolean) -> (listof number)
sort2: (listof name) (name name -> boolean) -> (listof name)
sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM)

Type variable: ITEM.

(-) Map

map1: (number -> number) (listof number) -> (listof number)
map2: (name -> name) (listof name) -> (listof name)
map: (x -> x) (listof x) -> (listof x)

Type variable: x.

(-) Project

project1: (listof (listof symbol)) ((listof symbol) -> symbol) -> (listof
symbol)
project2: (listof (listof name)) ((listof name) -> name) -> (listof name)
project: (listof (listof x)) ((listof x) -> x) -> (listof x)

Type variable: x.

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] htdp: functions of section 19 violate the grammar of section 8

2014-09-11 Thread Daniel Bastos
It makes sense, yes. I mean, the overall message. But I'm trying to
pinpoint where the grammar of section 8 tells me "no, you cannot put a
function name in an argument of an application". I read again the
entire section 8, am reading section 19 again and I still don't see
it. I'll write my argument and you'll spot a false statement
somewhere.

(By the way, I know the language Beginning Student doesn't allow a
function name to be passed as an application argument. I've checked
it.)

It's clear that a primitive cannot be passed as an argument in the
grammar of section 8. Here's my proof. An application in that grammar
is of the form (  ...). Since primitives do not appear
in this form, it cannot be present in an application. (We're done.)

However, any expression /can/ be used as an application argument
because an application is of the form (  ...). What are
the possible expressions in the grammar of section 8? It begins with
. When I define a user-defined function, its name is a .
Therefore, any user-defined function's name is an expression and hence
can appear in an application.

But section 20 says that "[an argument [...] is an expression, and the
class of expressions does not contain primitive operations and
function names. It does contain variables, but we agreed that they are
only those variables mentioned in variable definitions and as function
parameters."

This must be where the problem is. Where did we agree to that? I went
back to section 8 to see what a  is. "The first category is that
of variables, which are the names of functions and values." So a 
names a function such as

  (define (f x) (* 2 x))

and so f should be allowed to appear as an application argument.
Doesn't that follow from the text?

Thank you!

On Wed, Sep 10, 2014 at 4:10 PM, Stephen Chang  wrote:
> The arguments are the   The function position is  or 
>
> Essentially, the grammar in sec20 extends sec8 with the ability to:
> - pass functions and primitives, like +, as arguments, and
> - compute the applied function in the function position instead of
> always using predefined s or s
>
> Does that make sense?

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] htdp: functions of section 19 violate the grammar of section 8

2014-09-10 Thread Daniel Bastos
I remember having had that question when I was at that chapter. I must
have thought I answered it, but I'm having it again and unable to
answer now. IOW, I'm confused.

I'm having difficulties with this phrase too. "First, the names of
functions and primitive operations are used as arguments in
applications."

What is an argument in application? I'm going to try to answer it. An
application is, according to the grammar of section 8,

   (  ...)

or

  (  ...)

So its arguments are , , ... and the final . Similarly,
the second application has arguments , , ..., . Is that
correct?

Thank you.

On Wed, Sep 10, 2014 at 3:25 PM, Stephen Chang  wrote:
> I believe it's answered in a subsequent paragraph?
>
> "The abstract functions of section 19 violate Scheme's basic grammar
> in two ways. First, the names of functions and primitive operations
> are used as arguments in applications. An argument, though, is an
> expression, and the class of expressions does not contain primitive
> operations and function names. It does contain variables, but we
> agreed that they are only those variables mentioned in variable
> definitions and as function parameters. Second, parameters are used as
> if they were functions, that is, the first position of applications.
> But the grammar of section 8 allows only the names of functions and
> primitive operations in this place."

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] htdp: functions of section 19 violate the grammar of section 8

2014-09-10 Thread Daniel Bastos
I have not been able to verify this statement.

  "As a matter of fact, the functions of section 19 violate the Scheme
grammar of section 8." -- First paragraph of section 20.

I think the statement is referring to functions such as filter1.

(define (filter1 rel-op alon t)
  (cond
[(empty? alon) empty]
[else (cond
   [(rel-op (first alon) t)
(cons (first alon)
  (filter1 rel-op (rest alon) t))]
   [else
(filter1 rel-op (rest alon) t)])]))

It must be because of rel-op, I figure. But rel-op is a .
According to Figure 21 (the grammar of section 8), ( 
...) is an , so I think filter1 doesn't violate the grammar
of section 8.

Where am I wrong? Thank you!

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 20.2.4 ex:fancy-contracts-poly

2014-09-04 Thread Daniel Bastos
A candidate for a solution. (I'm not sure I'm correct regarding the
function project. The description says "a lists of lists" (which I
translate to (listof ITEM)) and "a function from lists to Xs", so I
wonder if the domain of this function-argument must be (listof ITEM)
or it could be more general such as (listof Y). I decided to imagine
that the domain of the function-argument would be items of the "list
of lists" and so I made it into (listof ITEM).

Thank you for your attention.

Exercise 20.2.4. Formulate general contracts for
the following functions:

1. sort, which consumes a list of items and a
function that consumes two items (from the list)
and produces a boolean; it produces a list of items.

2. map, which consumes a function from list items
to Xs and a list; it produces a list of Xs.

3. project, which consumes a list of lists and a
function from lists to Xs; it produces a list of Xs.

Compare with exercise 20.2.2.

Solution.

sort: (listof ITEM) (ITEM ITEM -> boolean) -> (listof ITEM)

map: ((listof ITEM) -> X) (listof ITEM) -> (listof X)

project: (listof (listof ITEM)) ((listof ITEM) -> (listof X)) -> (listof X)

(*) Comparison with exercise 20.2.2

For sort, we replaced number with X. So we generalized the type
of the list which we sort. The new procedure can sort a generic list.

For map, we generalized both the domain and co-domain of
the function consumed by map. Before, the consumed function
was only a mapping from numbers to numbers and now it is
a mapping from a generic domain ITEM to a generic co-domain X.

For project, we generalized the type of the list of lists. It was of
type symbol and now it can be a list of lists of any kind of item.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 20.2.3 ex:filter-contract

2014-09-03 Thread Daniel Bastos
A candidate for a solution.

;; Exercise 20.2.3. Use filter1 to develop a function that
;; consumes a list of symbols and extracts all those that
;; are not equal to 'car. Give filter1's corresponding contract.

;; Solution.

(define (filter1 rel-op alon t)
  (cond
[(empty? alon) empty]
[else (cond
[(rel-op (first alon) t)
 (cons (first alon)
   (filter1 rel-op (rest alon) t))]
[else
 (filter1 rel-op (rest alon) t)])]))

;; f: (listof symbol) -> (listof symbol)
;; consumes a (listof symbol), producing a (listof symbol) without
;; any occurrence of 'car
(define (f ls-of-sym)
  (local ((define (cmp sym1 sym2)
(not (symbol=? sym1 sym2
(filter1 cmp ls-of-sym 'car)))

(check-expect (f (list 'a 'b 'car 'x)) (list 'a 'b 'x))
(check-expect (f (list 'car 'car 'x 'car)) (list 'x))

;; The contract of filter1
;; filter1: (symbol symbol -> boolean) (listof symbol) symbol -> (listof symbol)

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 20.2.2 ex:fancy-contracts

2014-09-03 Thread Daniel Bastos
A candidate for a solution.

Exercise 20.2.2. Formulate contracts for the following functions:

1. sort, which consumes a list of numbers and a function that consumes
two numbers (from the list) and produces a boolean; sort produces a
list of numbers.

2. map, which consumes a function from numbers to numbers and a list
of numbers; it also produces a list of numbers.

3. project, which consumes a list of lists of symbols and a function
from lists of symbols to symbols; it produces a list of symbols.

Solution.

sort: (listof number) (number number -> boolean) -> (listof number)

map: (number -> number) (listof number) -> (listof number)

project: (listof (listof symbol)) ((listof symbol) -> symbol) -> (listof symbol)

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 20.2.1 ex:arrows-dd

2014-09-03 Thread Daniel Bastos
A candidate for a solution.

Exercise 20.2.1. Explain the following classes of functions:

1. (number  ->  boolean),
2. (boolean symbol  ->  boolean),
3. (number number number  ->  number),
4. (number  ->  (listof number)), and
5. ((listof number)  ->  boolean).

Solution.

  (1) consumes a number and produces a boolean;

  (2) consumes a boolean and a symbol and produces a boolean;

  (3) consumes three numbers and produces a number;

  (4) consumes a number and produces a list of numbers;

  (5) consumes a list of numbers and produces a boolean.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 20.1.2 ex:syn-funcs

2014-09-02 Thread Daniel Bastos
Exercise 20.1.2. Argue why the following sentences are legal
definitions:

(define (f x) (x 10))

(define (f x) f)

(define (f x y) (x 'a y 'b))

Solution. The relevant part of the grammar is the following.

   = (define (  ...) )
| (define  )
| (define-struct  (  ...))

(*) First definition

The LHS is a list of , since we find f and x as members of the
list and they're both variables. The RHS is a list consisting of a
 and a . That composes an , satisfying the first form
of . In other words,

  (define ( ) (  ) ( ) =
  (define ( ) ).

Therefore it's a legal .

(*) Second definition

Same LHS as the previous, so we need only check the RHS which is a
.  is a valid form of , so we have

  (define ( ) ) =
  (define ( ) ).

Therefore it's a legal .

(*) Third definition

The LHS is (  ), while the RHS is (  
), so we have

  (define (  ) (   )) =
  (define (  ) (   )) =
  (define (  ) ).

Therefore it's a legal .

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 20.1.1 ex:sem-funcs

2014-09-02 Thread Daniel Bastos
A candidate for a solution.

Exercise 20.1.1. Assume the Definitions window in DrScheme contains
(define (f x) x). Identify the values among the following expressions:

(1) (cons f empty)
(2) (f f)
(3) (cons f (cons 10 (cons (f 10) empty)))

Explain why they are values and why the remaining expressions are not
values.

Solution. First we consider (1). Here's the relevant part of the
grammar.

   = empty | (cons  )

   =  |  |  | empty | 
  |  (names of defined functions)
  | 

So (1) is a value because it is  of the form (cons  empty),
where f is  because it is a defined function.

Let's consider (3) before (2). (3) is a list of either  or ,
so (3) is  as well.

Now we consider (2). Here's the relevant part of the grammar.

 =
  | 
  | (  ...)

So (2) is ( ), a list of expressions, which is an , not
a . So (2) is not a value, although it's a legal expression.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 19.2.4 ex:para-non-empty

2014-08-29 Thread Daniel Bastos
Perhaps I didn't understand this exercise. The hint advises me to work with
a particular case and then generalize. I did this, but it seems that even
in a particular case the most natural solution seems to be the general one.
The generalization took place only in the data definition, but it didn't
seem to affect the function definition.

;; Exercise 19.2.4. Here is a parametric data
;; definition of non-empty lists:

;; A (non-empty-listof ITEM) is either
;; 1. (cons s empty), or
;; 2. (cons s l) where l is a (non-empty-listof ITEM)
;; and s is always an ITEM.

;; Develop the function last, which consumes
;; a (non-empty-listof ITEM) and produces the last
;; ITEM in that list.

;; Hint: Replace ITEM with a fixed class of data to
;; develop an initial draft of last. When finished,
;; replace the class with ITEM throughout the function
;; development.

;; Draft. a (non-empty-listof number) is either
;; 1. (cons s empty), or
;; 2. (cons s l) where l is a (non-empty-listof number)
;; and s is always a number.

;; last-number: non-empty-ls -> number
;; consumes a non-empty list of numbers and produces its last number
(define (last-number non-empty-ls)
  (cond
[(empty? (rest non-empty-ls))
 (first non-empty-ls)]
[else
 (last-number (rest non-empty-ls))]))

;; Generalizing to ITEM.

;; a (non-empty-listof ITEM) is either
;; 1. (cons s empty), or
;; 2. (cons s l) where l is a (non-empty-listof ITEM)
;; and s is always an ITEM.

;; last: non-empty-ls -> ITEM
;; consumes a non-empty list of ITEMs and produces its last ITEM
(define (last non-empty-ls)
  (cond
[(empty? (rest non-empty-ls))
 (first non-empty-ls)]
[else
 (last (rest non-empty-ls))]))

(check-expect (last-number (list 1 2 3 4 5)) 5)
(check-expect (last (list (list 1) (list 2) (list 3))) (list 3))
(check-expect (last '(a b c d e f)) 'f)

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 19.1.6 ex:abs-sort

2014-08-29 Thread Daniel Bastos
A candidate for a solution.

;; sort1 : list-of-numbers  ->  list-of-numbers
;; to construct a list with all items from alon in descending order
(define (sort1 cmp alon)
  (local ((define (sort alon)
(cond
  [(empty? alon) empty]
  [else (insert (first alon) (sort (rest alon)))]))
  (define (insert an alon)
(cond
  [(empty? alon) (list an)]
  [else (cond
  [(cmp an (first alon)) (cons an alon)]
  [else (cons (first alon) (insert an (rest
alon)))])])))
(sort alon)))

(check-expect (sort1 < (list 2 3 1 5 4)) (list 1 2 3 4 5))
(check-expect (sort1 > (list 2 3 1 5 4)) (list 5 4 3 2 1))

Source:
http://www.htdp.org/2003-09-26/Solutions/abs-sort.html
No Solution Written, yet Unfortunately, the solution to this exercise has
not yet been written. To submit a solution you have written to this
problem, or to complain that the solution isn't available, please contact Robby
Findler

.

To see the list of solutions, visit the table of contents
. Each of the
hyperlinked exercise numbers has a solution.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] missing solution 16.3.3 ex:file-du

2014-08-08 Thread Daniel Bastos
A candidate for a solution.

;; model 3
(define-struct file (name size content))
(define-struct dir (name dirs files))

;; files:
(define hang (make-file 'hang 8 empty))
(define draw (make-file 'draw 2 empty))
(define read (make-file 'read! 19 empty))
(define one  (make-file 'part1 99 empty))
(define two  (make-file 'part2 52 empty))
(define thre (make-file 'part3 17 empty))
(define rdme (make-file 'read 10 empty))

;; directories:
(define Code (make-dir 'Code '() (list hang draw)))
(define Docs (make-dir 'Docs '() (list read)))
(define Libs (make-dir 'Libs (list Code Docs) '()))
(define Text (make-dir 'Text '() (list one two thre)))
(define Top  (make-dir 'TS (list Text Libs) (list rdme)))

;; dur-dir :: dir -> number
;; consumes a directory producing a sum of the list of files in each.
;; to the sum, it'll add 1 for each directory it finds. (we're assuming
;; each directory is of size 1).
(define (du-dir d)
  (+ 1 (sum-files (dir-files d)) (du-dir-subdir (dir-dirs d

(define (du-dir-subdir ls)
  (cond
   [(empty? ls) 0]
   [(dir? (first ls))
(+ (du-dir (first ls))
   (du-dir-subdir (rest ls)))]))

;; sum-files :: ls-of-files -> number
;; consumes a list of files producing the sum of their sizes
(define (sum-files ls)
  (cond
   [(empty? ls) 0]
   [else (+ (file-size (first ls))
(sum-files (rest ls)))]))

;; tests
(check-expect
 (sum-files (list hang draw))
 10)

(check-expect
 (sum-files empty)
 0)

(check-expect
 (du-dir Libs)
 (+ 8 2 19 1 1 1))

Source:
> http://www.htdp.org/2003-09-26/Solutions/file-du.html
> No Solution Written, yetUnfortunately, the solution to this exercise has
> not yet been written. To submit a solution you have written to this
> problem, or to complain that the solution isn't available, please contact 
> Robby
> Findler
> 
> .
>
> To see the list of solutions, visit the table of contents
> . Each of the
> hyperlinked exercise numbers has a solution.
>

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] on emacs keybindings in dr racket (Was: Re: on contract violation after adding 1471 strings to a BST)

2014-08-08 Thread Daniel Bastos
On Fri, Aug 8, 2014 at 9:34 AM, Matthias Felleisen 
wrote:

> Why not turn on Emacs bindings inside of DrRacket?


I'll take the advice.

BTW, some of my preferences windows don't show nicely because I use large
fonts on my system. (See image attached.) Also, I think I only found the
option being what I want by reading

  http://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html

With all my newbieness, I was looking for something like "enable EMACS
keybindings". (But now I have the nice EMACS keybindings. Thank you.)

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] on contract violation after adding 1471 strings to a BST

2014-08-08 Thread Daniel Bastos
On Tue, Aug 5, 2014 at 5:43 PM, Matthias Felleisen 
wrote:

> Warning: you switched from a teaching language to full Racket.
> The former would have caught this mistake, which is why we
> designed them for HtDP. Racket is for grown-up parenthesis
> eaters -- who want the behavior of cond that you just experienced,
> or so I am told. -- Matthias
>

Is it possible to use the beginning-student-with-list-abbreviation language
from a REPL inside the GNU EMACS?

I copied the prelude that DrRacket adds when I save a
beginning-student-language file with it and ran it with racket. I get

%racket beginner.rkt
cond: all question results were false
  context...:
   /home/dbastos/public_html/rkt/beginner.rkt: [running body]
%

(Very nice.) But I'm unable to run the prelude inside the REPL. That'd be
this passage below.

#reader(lib "htdp-beginner-reader.ss" "lang")((modname bst)
(read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor
repeating-decimal #f #t none #f (

After #reader, it seems to always expect more and more input. So my
strategy didn't work for the REPL.

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] on contract violation after adding 1471 strings to a BST

2014-08-05 Thread Daniel Bastos
Thanks for pointing this out.

On Tue, Aug 5, 2014 at 5:43 PM, Matthias Felleisen 
wrote:

> Warning: you switched from a teaching language to full Racket.
> The former would have caught this mistake, which is why we
> designed them for HtDP. Racket is for grown-up parenthesis
> eaters -- who want the behavior of cond that you just experienced,
> or so I am told. -- Matthias

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] on contract violation after adding 1471 strings to a BST

2014-08-05 Thread Daniel Bastos
On Tue, Aug 5, 2014 at 5:06 PM, Jens Axel Søgaard 
wrote:

> What happens in create-bst-word, when the word to inserted is the same
> as (node-word bst) ?


Aha! I see. It returns void because there is no case for when the string is
equal.

> (void? (create-bst-word (create-bst-word false "dan") "dan"))
#t

I patched it with an else-case now.

(define (create-bst-word bst str)
  (cond
   ((false? bst)
(make-node str false false))
   ((string? str (node-word bst)) ;; insert at the right
(make-node (node-word bst)
   (node-left bst)
   (create-bst-word (node-right bst) str)))
   (else (make-node (node-word bst)
(node-left bst)
(node-right bst)

> (void? (create-bst-word (create-bst-word false "dan") "dan"))
#f

Thank you.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] on contract violation after adding 1471 strings to a BST

2014-08-05 Thread Daniel Bastos
After studying chapter 14 of HtDP, I decided to try putting strings into a
BST. The code below works with a few strings. I have a file with 22064
strings --- one per line. Up until 1471 words, it works. With 1472 it
yields a contract violation.

> (length (read-words))
22064

> (create-bst-word-from-list (take (read-words) 1471))
#

> (create-bst-word-from-list (take (read-words) 1472))
node-word: contract violation
  expected: node?
  given: #
  context...:
   /home/dbastos/public_html/rkt/functions.rkt:974:0: create-bst-word
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list
   /home/dbastos/public_html/rkt/functions.rkt:987:0:
create-bst-word-from-list...

>

It seems node-word says I gave it a #. Perhaps my list of words
contains a #, but when I search for it, I do not find it.

> (define ls (read-words))
> (length ls)
22064
> (length (filter string? ls))
22064
> (filter void? ls)
()

So I'm perplexed.

(define-struct node (word left right))

(define (create-bst-word bst str)
  (cond
   ((false? bst)
(make-node str false false))
   ((string? str (node-word bst)) ;; insert at the right
(make-node (node-word bst)
   (node-left bst)
   (create-bst-word (node-right bst) str)

(define (create-bst-word-from-list ls)
  (cond
   ((empty? ls) false)
   (else
 (create-bst-word (create-bst-word-from-list (rest ls)) (first ls)

(define (read-lines in)
  (let* ((ln (read-line in)))
(cond
 ((eof-object? ln) empty)
 (else (cons ln (read-lines in))

(define (read-words)
  (call-with-input-file "words" read-lines))

Thank you in advance for any information.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] changing source code with application still running

2012-10-10 Thread Daniel Bastos
Here's a quote from Paul Graham --- quoting from
http://bc.tech.coop/blog/040223.html.

"When one of the customer support people came to me with a report of a
bug in the editor, I would load the code into the Lisp interpreter and
log into the users' account. If I was able to reproduce the bug I'd
get an actual break loop, telling me exactly what was going wrong.
Often I could fix the code and release a fix right away. And when I
say right away, I mean while the user was still on the phone. "

I have been trying to understand *how* this is done. I'd hope that
this is also possible in Racket. But let me ask about the following
specific situation.

Say I have some application running. I told the shell

 ./run_my_application &

Now, while using it, I notice a bug somewhere. How do I change the
code and see its new effect without shutting down and rerunning the
application?

Thank you.

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] db.plt, long query

2012-09-10 Thread Daniel Bastos
2012/9/10 Daniel Bastos :
> It seems that if I give a very long string to query-rows, I get the
> following message.
>
>  query-rows: unsupported type: (typeid string)
>
> Short queries are no problem. How do you guys do this properly?

The problem is not the length of the query, but a query which grabs a
column whose datatype the library does not support. The documentation
suggests casting the datatype to a supported type.

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] db.plt, long query

2012-09-10 Thread Daniel Bastos
It seems that if I give a very long string to query-rows, I get the
following message.

 query-rows: unsupported type: (typeid string)

Short queries are no problem. How do you guys do this properly?

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] racket's template system: expand: unbound identifier

2011-11-25 Thread Daniel Bastos
2011/11/25 Jay McCarthy :
> The lack of a space between ] and { is important. Notice that the example in
> the documentation is
> @in[c clients]{
>    @(car c), @(cdr c)
>   }
> not
> @in[c clients] {
>    @(car c), @(cdr c)
>   }

Indeed. Thanks. I wonder why there is such requirement. Does it avoid
a difficulty in the parser or scanner?

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] racket's template system: expand: unbound identifier

2011-11-24 Thread Daniel Bastos
Good evening, gentlemen.

I'm studying

  http://docs.racket-lang.org/web-server/templates.html

to see how web development is done in Racket. Having written a first
hello world using templates, I'm wishing to use the @in[] call. So I
wrote

%cat templates1.rkt
#lang racket
(require web-server/servlet
 web-server/servlet-env
 web-server/templates)

(define (start req)
  (response/doit
(let ([friends
   (list (cons "John" "Smith")
 (cons "Jack" "Smith")
 (cons "Joseph" "Smith"))])
   (include-template "friends.html"

(define (response/doit text)
  (response/full
200
#"Okey dokey"
(current-seconds)
TEXT/HTML-MIME-TYPE
empty
(list (string->bytes/utf-8 text

(serve/servlet start
  #:port 80
  #:servlet-path "/"
  #:command-line? #t)
%

I'm getting

%racket templates1.rkt
friends.html:4:18: expand: unbound identifier in module in: c

 === context ===
standard-module-name-resolver

%cat friends.html

  
   @in[c friends] {
@(car c), @(cdr c)
   }
  
%

Could you point towards a direction where I can always take a further
step to dig in and find what's going wrong? (Although I'm so new at
the technology that I might be unable to follow instructions.)

Here's what I'm trying to do. I wrote templates2.rkt to test the
include-template function.

%cat templates2.rkt
#lang racket
(require web-server/servlet
 web-server/servlet-env
 web-server/templates)

(define (start req)
  (response/doit
(include-template "nothing.html")))

[... more code omitted ...]

%cat nothing.html
hi

%rlwrap racket
Welcome to Racket v5.2.0.3.
> (load "templates2.rkt")
> (expand (include-template "nothing.html"))
reference to undefined identifier: include-template

I thought that by loading templates2.rkt, I could spare me from
requiring web-server/templates.

> (require web-server/templates)
> (include-template "nothing.html")
"hi"

> (expand (include-template "nothing.html"))
#

> (syntax->datum (expand (include-template "nothing.html")))
''"hi"

> (syntax->datum (expand (include-template "friends.html")))
reference to undefined identifier: friends

 === context ===
/home/dbastos/plt/collects/racket/port.rkt:63:0: with-output-to-string
/home/dbastos/plt/collects/racket/private/misc.rkt:87:7

My plan was to see a little further what the code in friends.html is
doing, but then I need to bind friends to something before I try to.
But if I do that, the other c-unbound-identifier error will blow
anyway and I won't see the code. I wish I could see the code before
executing it. How do you guys do it?
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users