Re: [racket] CAM

2013-01-25 Thread Richard Cleis
Years ago, I heard about AutoLisp from a non-programmer that used it. I think 
Racket would be a fine tool for making a newer and better one. I don't dare 
risk asking the originator of this thread for an example, for he will belittle 
me without ever giving an example, and tell me that I only use Racket for hobby 
projects.

http://www.woodweb.com/knowledge_base/How_to_Generate_CNC_Code_Using_AutoCAD_and.html

rac

On Jan 25, 2013, at 7:07 AM, Tim Brown wrote:

> On 25/01/13 03:44, Hugh Aguilar wrote:
>> Do you guys know if anybody has done any CAM work in Racket, Scheme,
>> Lisp, etc.? Perhaps one of these 30-day wonders from the PLTgames
>> contest. :-)
> 
> Given as the 2nd PLT games contest is running, and the first one was a
> Turing tarpit; probably not.
> 
>> Actually, I'd be interested in hearing about any language used as a
>> framework for CAM (I have no patience for point-and-click CAM software,
>> but I'm only interested in DSL CAM systems).
> 
> I believe there are a number (>= 1) of CAM programmers using SWI Prolog,
> and active on the SWI Prolog list.  I guess there are certain spacial
> problems that are more "appropriately" solved using Prolog.  It might be
> worth raising a question over there, too.  [Nobody's done anything with
> datalog have they?]
> 
> Tim
> 
> -- 
> Tim Brown   | City Computing Limited|
> T: +44 20 8770 2110| City House, Sutton Park Road  |
> F: +44 20 8770 2130| Sutton, Surrey, SM1 2AE, GB   |
> ---|
> BEAUTY:  What's in your eye when you have a bee in your hand   |
> ---'
> City Computing Limited registered in London No. 1767817.
> Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE
> VAT number 372 8290 34.
> 
> Racket Users list:
> http://lists.racket-lang.org/users


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


Re: [racket] OFFTOPIC - Quote on Programming

2013-03-21 Thread Richard Cleis
My experience is the same. But try to explain to a program or project manager 
that at least four things gradually change to complete a project: design, code, 
tests, and docs. I am no longer expecting to ever work on a project where the 
leaders do not insist each of those is a milestone completed in some exact 
order that was preconceived by someone who never finished a good project.

rac

On Mar 19, 2013, at 2:29 PM, Patrick Li wrote:

> My personal experience is that a good and detailed design is hard to
> get to *without* doing the coding.
>  -Patrick
> 
> On Tue, Mar 19, 2013 at 1:50 PM, Jos Koot  wrote:
>> One remark down intermixed in your email.
>> Jos
>> 
>>> -Original Message-
>>> From: users-boun...@racket-lang.org
>>> [mailto:users-boun...@racket-lang.org] On Behalf Of Hendrik Boom
>>> Sent: martes, 19 de marzo de 2013 15:15
>>> To: users@racket-lang.org
>>> Subject: Re: [racket] OFFTOPIC - Quote on Programming
>>> 
>>> I forget where that quotation came from originally, but it
>>> antedated the
>>> days where internal documentation was the norm.
>>> 
>>> On Tue, Mar 19, 2013 at 06:20:57AM +0100, Jos Koot wrote:
 Well, that may depend on how you define "clever code".
>>> Surely it is clever
 to write well documented code that can easily be
>>> understood, debugged,
 maintained and reused by yourself and by others.
>>> 
>>> The "clever" refers to cleverness merely in producing a
>>> foemalism that
>>> appears to work.
>>> 
 Understanding may require
 knowledge of the discipline the code is written for, of
>>> course. In my
 opinion it helps a lot first finishing the documentation
>>> and the design
 (both user and 'inside' docs) before starting coding.
>>> 
>>> You're talking about metacleverness -- the know-yourself kind of
>>> cleverness that acknowledges your own limitations and take them into
>>> account.
>>> 
 With good and well
 described design it is even possible to leave the coding to
>>> another person,
 just like an architect designs a building and constructors build it.
 My 2c, Jos
>>> 
>>> I've never found it to be feasible to leave the coding to another
>>> person, except in cases where the remaining coding is so
>>> trivial that a
>>> machine could do it.
>> 
>> I have experienced some good things leaving the coding to others. I think
>> that in some cases a good and detailed design makes coding almost trivial.
>> 
>>> 
>>> [ In which case it makes sense to use a compiler.  :-) ]
>>> 
>>> -- hendrik
 
 From: users-boun...@racket-lang.org
>>> [mailto:users-boun...@racket-lang.org]
 On Behalf Of Harry Spier
 Sent: martes, 19 de marzo de 2013 2:56
 To: users
 Subject: [racket] OFFTOPIC - Quote on Programming
 
 
 I found this quote on a blog and couldn't help sharing it :-)
 
 
 "Debugging is twice as hard as writing the code in the first place.
 Therefore if you write the code as cleverly as possible, you are by
 definition not smart enough to debug it." Brian Kernigan
 
>>> 
 
  Racket Users list:
  http://lists.racket-lang.org/users
>>> 
>>> 
>>>  Racket Users list:
>>>  http://lists.racket-lang.org/users
>> 
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



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


[racket] Thanks for Math

2013-04-20 Thread Richard Cleis
Thanks for the math library. I started using some of the linear algebra 
functions for my paid programming, and have had zero trouble with any of it. 
Matrix-solve works like a dream, and the docs are on the mark.

I have to wonder what would happen if a program manager were looking over my 
shoulder on the rare occasion that I commit a Contract Violation for issues 
like non-invertible matrices. PMs are a humorous lot in regards to violation of 
contractual terms. 

rac



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


Re: [racket] Thanks for Math

2013-04-22 Thread Richard Cleis
Recently I used it for estimating orientation parameters of telescopes. Inputs 
are the locations of stars, outputs are telescope coordinates, parameters 
describe the relationship of axes to each other and to the earth.

In matrix-solve, MX=B are
M : J[transpose]J, where the J matrix is filled with numerically computed 
derivatives of each parameter vs outputs.

B : J[transpose]E, where E is filled with the errors in each axis as measured 
by observing stars

X : the changed in parameters that are to be solved on each iteration of the 
estimator

Due to numerous orthogonal components and parallel parameters (for certain 
pointing directions), the matrix library has to be rigorously written, else the 
iterations die of round-off errors etc. I had several choices, but given the 
high caliber people that write Racket code, I figured I could go with 
matrix-solve and expect it to work.

rac


On Apr 21, 2013, at 11:11 AM, Joe Gilray wrote:

> Yes, the math library is awesome.  Many thanks.
> 
> Richard, what are you using it for? (if you are liberty to say, of course).
> 
> -joe
> 
> 
> On Sat, Apr 20, 2013 at 8:28 PM, Richard Cleis  wrote:
> Thanks for the math library. I started using some of the linear algebra 
> functions for my paid programming, and have had zero trouble with any of it. 
> Matrix-solve works like a dream, and the docs are on the mark.
> 
> I have to wonder what would happen if a program manager were looking over my 
> shoulder on the rare occasion that I commit a Contract Violation for issues 
> like non-invertible matrices. PMs are a humorless lot in regards to violation 
> of contractual terms.
> 
> rac
> 
> 
> 
>   Racket Users list:
>   http://lists.racket-lang.org/users
> 


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


Re: [racket] Why experienced programmers don’t use comments?

2013-07-09 Thread Richard Cleis
We continue to edit, comment, and document code as if it will be printed on 
paper and read from top to bottom. Instead, editors should manage templates for 
comments and documentation that can instantly be controlled (clutter switches, 
arguably). The software leads need a way of affecting the requirements that 
these aids impose.

I am an experienced programmer and believer in the teachings of HtDP, but it is 
impractical to convince others of the benefits of taking the time to (for 
example) describe inputs and outputs... as schedules are gradually morphing 
into nonsense. Furthermore, changing arguments as code evolves screws up 
whatever comments and documentation have already been made. Development 
environments that aid programmers in maintaining such non-compiled portions of 
programs have been attempted, but they are hardly good enough or universally 
accepted.

I suppose that was a long way of saying that it is too difficult maintain 
thorough comments, so experienced programmers instead use their heads to 
minimize them.

rac



On Jul 8, 2013, at 3:41 PM, Ben Duan wrote:

> Dear All,
> 
> I have a question here. There’s an extensive use of comments in HtDP. But 
> there are few comments in experienced programmers’ code, for example in 
> racket’s source code. Why is that?
> 
> Thanks,
> Ben
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



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


Re: [racket] Numbers with dimensions

2013-10-24 Thread Richard Cleis
This discussion reappears occasionally, and there are some accomplishments. You 
can start here to at least figure out how to search for more info:

http://lists.racket-lang.org/users/archive/2011-November/049198.html

rac

On Oct 24, 2013, at 4:51 PM, Alvin Schatte wrote:

> Is there a library or package that combines numbers and their operations with 
> dimensions that may be associated with them?
> Alvin Schatte
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Numbers with dimensions

2013-10-26 Thread Richard Cleis
A few years ago, my approach (which didn't get very far) was to internally 
maintain values in some chosen internal units; this input conversion occurred 
once, when variables were defined or otherwise introduced into the program. The 
conversion to the user-desired units then took place once via functions of the 
value and only the user units. The goal was to have no computational overhead 
during the computations, and to only need conversion between the user and 
internal units when data is introduced or extracted.

I stopped when I had the feeling that this subject has been studied much over 
the decades, so I needed to engage in the research before writing a few dozen 
pages (at least) of software.

rac


On Oct 26, 2013, at 9:48 AM, Matthias Felleisen wrote:

> 
> The last line applies to my thoughts not yours. 
> 
> As someone else indicated, I think we should experiment with 'dimension' 
> (distance, time) vs 'units' (meters vs yards, seconds vs hours). This 
> separation injects a hierarchy that could be useful. 
> 
> I'd really like to see some experimentation here because people haven't 
> explored the space much and Racket could help explore a #lang metric/racket 
> and even #lang typed/metric/racket. 
> 
> -- Matthias
> 
> 
> 
> 
> 
> On Oct 26, 2013, at 11:36 AM, Matthias Felleisen wrote:
> 
>> 
>> 1. I would hope that some generics might help here. 
>> 2. I see a need for struct mixins here because meter isn't a refinement per 
>> se but some 'attribute'. Then you could mixin several different units and I 
>> may have both m and m-1. 
>> 
>> Data representation not fully thought thru. -- Matthias
>> 
>> 
>> 
>> 
>> 
>> On Oct 26, 2013, at 11:26 AM, Laurent wrote:
>> 
>>> How would you represents quantities like 2 kg.m^2/s^-2 with that?
>>> And how would you convert from mi/h to m/s?
>>> 
>>> Anyway, I've started adding in some converters:
>>> https://github.com/Metaxal/measures/blob/master/converters.rkt
>>> 
>>> Some more to come, but I may not be able to work on it for very long for 
>>> now.
>>> 
>>> Laurent
>>> 
>>> 
>>> On Sat, Oct 26, 2013 at 5:05 PM, Matthias Felleisen  
>>> wrote:
>>> 
>>> 
>>> Wouldn't we want something like this: 
>>> 
>>> #lang racket
>>> 
>>> (module+ test (require rackunit))
>>> 
>>> (struct distance (value) #:transparent) ;; this should be abstract 
>>> (struct yard distance () #:transparent)
>>> (struct meter distance () #:transparent)
>>> 
>>> ;; distance distance -> distance 
>>> 
>>> (module+ test
>>>   (check-equal? (d+ (yard 1) (yard 2)) (yard 3))
>>>   (check-equal? (d+ (yard 1) (meter 2)) (meter (+ .9 2)))
>>>   (check-equal? (d+ (meter 1.8) (yard 1)) (yard (+ 2.0 1)))
>>>   (check-equal? (d+ (meter 2) (meter 1)) (meter 3)))
>>> 
>>> (define (d+ d1 d2) 
>>>   (match (list d1 d2)
>>> [(list (struct yard (value)) (struct yard (value2))) (yard (+ value 
>>> value2))]
>>> [(list (struct yard (value)) (struct meter (value2))) (meter (+ 
>>> (yard->meter value) value2))]
>>> [(list (struct meter (value2)) (struct yard (value))) (yard (+ 
>>> (meter->yard value2) value))]
>>> [(list (struct meter (value)) (struct meter (value2))) (meter (+ value 
>>> value2))]))
>>> 
>>> ;; distance distance-constructor -> distance 
>>> 
>>> (module+ test 
>>>   (check-equal? (conversion (yard 3) meter) (meter (* 3 .9
>>> 
>>> (define (conversion x d)
>>>   (match x 
>>> [(struct yard (y)) (if (eq? yard d) x (meter (yard->meter y)))]
>>> [(struct meter (y)) (if (eq? yard d) (yard (meter->yard y)) x)]))
>>> 
>>> 
>>> ;; auxiliaries 
>>> (define (yard->meter v) (* .9 v))
>>> (define (meter->yard v) (/ v .9))
>>> 
>>> -- Matthias
>>> 
>>> 
>>> 
>>> On Oct 26, 2013, at 7:20 AM, Laurent wrote:
>>> 
 Ok, so I just hacked together a small lib for handling numbers with unit 
 symbols and exponents:
 
 Quick example:
 > (measure->value
(m* '(18 s) 
'(1600 km (h -1))
'(1000 m (km -1))
'(1/3600 h (s -1
 '(8000 m)
 
 You can get it with:
 $ raco pkg install measures
 or from the File menu in DrRacket, if you have a recent version of Racket 
 (strictly > 5.3.6).
 
 Examples and details here:
 https://github.com/Metaxal/measures
 
 HTH,
 Laurent
 
 
 On Fri, Oct 25, 2013 at 12:51 AM, Alvin Schatte  
 wrote:
 Is there a library or package that combines numbers and their operations 
 with dimensions that may be associated with them?
 Alvin Schatte
 
 
   Racket Users list:
   http://lists.racket-lang.org/users
 
 
 
  Racket Users list:
  http://lists.racket-lang.org/users
>>> 
>>> 
>> 
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Newbie question on abstraction and the built in random function

2013-12-19 Thread Richard Cleis
You might want your encoding-scheme to be a function, 
and you want to evaluate that function inside generate-chromosome:

(define (generate-chromosome encoding-scheme number-of-genes)
  (cond  [(zero? number-of-genes) empty]
[else (cons (encoding-scheme)
 (generate-chromosome encoding-scheme (sub1 
number-of-genes)))]))

(define (binary-encoding-scheme)
  (random 2))
(define (value-encoding-scheme)
  (random))

(generate-chromosome binary-encoding-scheme 10)
(generate-chromosome value-encoding-scheme 10)

(0 1 1 1 1 1 0 1 1 0)
(0.17586764776624525
 0.13437314563189037
 0.585523111696543
 0.6533766686688987
 0.09071850144989983
 0.8804515074319006
 0.6998388642832832
 0.599233672637633
 0.5238661544779689
 0.72734166222789)
> 


rac



On Dec 19, 2013, at 7:42 PM, Rian Shams wrote:

> Hello All,
> 
> I am new to Racket and just started building an evolutionary computing module 
> to supplement my research and learn more about Racket.
> 
> When it comes to representing a chromosome, there are many encoding schemes 
> one can choose from. To start I would like to build a function that lets the 
> user choose the encoding scheme they would like by being able to directly 
> insert it into the function call. So far I have created this:
> 
> (define (generate-chromosome encoding-scheme number-of-genes)
>   (cond  [(zero? number-of-genes) empty]
> [else (cons encoding-scheme
>  (generate-chromosome encoding-scheme (sub1 
> number-of-genes)))]))
> 
> Two popular encoding schemes are the binary encoding scheme and the real 
> value encoding scheme:
> 
> (define binary-encoding-scheme
>   (random 2))
> (define value-encoding-scheme
>   (random))
> 
> So then calling this function using the binary encoding scheme:
> 
> (generate-chromosome binary-encoding-scheme 10)
>  
> gives either a list of only ten 1's or a list of only ten 0's. Random only 
> works once and whatever the first random value is stays and doesn't change.
> 
> How would I make random re-evaluate each time given that I want it to be 
> included in the definition of an encoding scheme?
> 
> As an alternate, the function below works when I directly include (random 2) 
> in for a value in the encoding scheme, but I prefer the structure of the 
> above function.
> 
> (define (generate-chromosome-2 number-of-genes)
>   (cond [(zero? number-of-genes) empty]
>[else (cons (random 2) ;binary-encoding-scheme
> (generate-chromosome-2 (sub1 number-of-genes)))]))
> 
> So the function call
> (generate-chromosome-2 10) gives the desired result, but doesn't fit the 
> needed structure.
> 
> Any help would be much appreciated. 
> 
> Best Regards,
> -- 
> Rian Shams
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] fruit flies

2011-09-12 Thread Richard Cleis
On iPhone3, I get 25 Log errors like:
JavaScript Log 1195.

Others are on 1299, 1204, 1222...

It shows 10 horizontal bars of various colors.

RAC

On Sep 12, 2011, at 11:47 AM, Danny Yoo  wrote:

> I wanted to share another small web-world demonstration in Whalesong.
> 
> Try this in Google Chrome:
> 
>http://hashcollision.org/whalesong/examples/boid/boid.html
> 
> Source code:
> 
>http://hashcollision.org/whalesong/examples/boid/boid.rkt
>http://hashcollision.org/whalesong/examples/boid/index.html
> 
> 
> What makes this program interesting is that I really am only touching
> the left and top css attributes on each clock tick, as opposed to
> redrawing the whole scene (as would be demanded in a regular world
> program).  Inspect Element in Chrome should bear this out.
> 
> I should probably call this program "fruit-flies".  In any event, this
> works on Chrome, but I haven't been able to successfully make it run
> under other browsers.  I've heard that it works in Safari 5.1 as well.
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Quoted expressions in #lang racket

2011-09-18 Thread Richard Cleis

On Sep 18, 2011, at 7:45 AM, Racket Noob wrote:

>  
> > You keep thinking (1 2 3) is the canonical form of a list. It is
> > not. It's just a particular *print representation* of list. So is
> > # or one of the many alternatives Eli proposed.
> >
>  
> Oh, I understand that. It's just that I don't understand why you (i.e. Racket 
> implementers) choose Racket by default prints list this way (different than 
> all other lisps). I think this choice can confuse beginners (and all other 
> users who switches from different lisp implementations and expects 
> "traditional" REPL behaviour). 

They partly made the choice for people like me, who didn't experience their 
courses or work through the the early chapters in HtDP; our group is still 
suffering from software I wrote before I understood the difference between the 
R and P in REPL (using several earlier versions of Scheme). I believe the 
Racket REPL would have eliminated that confusion. I also find flights over the 
ocean are more comfortable with turbine engines than piston engines.

rac

>  
> > Your attempt to use an interpreter model is commendable but falls
> > short. That is because you only described the READ and EVAL steps of
> > a REPL. The L(oop) is not relevant here, but the P(rint) is actually
> > the most critical part, and that's the one you left out of your
> > attempt at explaining what's happening.
> > 
> > Also, Matthias asked you about substituting answers inside bigger
> > expressions. You gave him a mechanical answer of why (you think) it
> > won't work, but you failed to understand the bigger point he was
> > trying to make in the first place.
> > 
> > Shriram
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users


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


Re: [racket] Racket in Industry Apologia (was Re: Racket Apology)

2011-10-02 Thread Richard Cleis

On Oct 2, 2011, at 12:45 PM, Brian Mastenbrook wrote:

> On 09/30/2011 02:07 PM, John Clements wrote:
>> Racket is an experimental language (cf. Shriram's "hothouse"). We are
>> *constantly* experimenting with the language, and on another level,
>> we have a language that's designed to enable *your* language
>> experiments. That's what makes it an exciting language to work with
>> and on, and why it has design features that are still years away from
>> appearing in mainstream languages.
>> 
>> That's *also* the reason that you'll almost never see Racket used in
>> industry. It's a language that doesn't compromise its ideals, and is
>> constantly innovating, and if you're a business that's looking for a
>> stable language with a broad supply of programmers, Racket would be
>> an extremely surprising choice.
> 
> I feel compelled to point out that there's a big difference between 
> "industry" as a whole and "business that's looking for a stable language with 
> a broad supply of programmers". Just as most businesses aren't the big 
> corporations everyone likes to rant about, not all (and maybe even not most?) 
> tech companies aren't big companies where it's acceptable to throw warm 
> bodies with a passable knowledge of Java or Python at a problem. Outside of 
> the large companies of the world, Racket's rapid evolution is not a problem 
> and not even a detriment. 
...

It was not long ago that Java and Python were unacceptable for the same excuses 
that are now applied to Racket and any other 'new' alternative.

What is next?

rac


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


Re: [racket] Functions as symbols

2011-10-07 Thread Richard Cleis
The long answer to your question depends on how you are using the capability. 
You don't have to form the whole expression before evaluating it, and you don't 
need to use apply. For example, you can define a symbol in racket, then run the 
program:

#lang racket/base

(define sym '+)
[run the above]
 
Now you can recover the native function in the interactions pane like this:

> (define f (eval sym))
>

Then, f is what you want:

> (f 1 2)
> 3

The trouble is, the above is a subtle concoction of the top layer and the 
implied module created by #lang racket/base

You can read Guide:Racket, section 15.1, to figure out what you really need to 
do.

rac



On Oct 7, 2011, at 1:53 AM, Mark Carter wrote:

> I would like to treat a symbol as a function, and apply it to some arguments. 
> In other words, if I did something like
> (define sym '+)
> (apply '+ '(1 2))
> I would obtain the answer 3. Is there any way I can do this? The following 
> works, but I'm wondering if it's the best way:
> (eval `(apply ,sym '(1 2)))
> A more basic question would be: is there any way I can convert from '+ to + - 
> i.e. a symbol to a function?
> 
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


[racket] (read) interactions

2011-10-28 Thread Richard Cleis
After a user enters information in the box that follows (read), a program 
prints progress lines until a task is complete. The entry box remains until the 
program finishes; it floats downward with the latest line. 

Is it possible to make the box disappear after the data entry is complete? 

rac


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


Re: [racket] (read) interactions

2011-11-02 Thread Richard Cleis
Agter the user strikes the return key, the read window apparently is no longer 
functional. It does not seem possible to read any more than the first 
expression after the first interaction, or read anything else that is typed in 
the window later. Why is it displayed after the initial entry?

rac

On Nov 1, 2011, at 12:50 PM, Robby Findler wrote:

> It is possible, but the tricky part is figuring when they are done.
> Right now, the box first appears when the program tries to read a
> character (perhaps via a call to read-line, perhaps via a call to read
> or read-syntax). It does seem possible to hide the box when a) there
> is no data that the program hasn't read, still in the box and b) the
> program has not tried to read any new data, but I worry about the case
> where the box flickers as the user enters a line of data and then the
> program processes that line a little bit before reading the next line.
> 
> Any ideas?
> 
> Robby
> 
> On Sat, Oct 29, 2011 at 12:32 AM, Richard Cleis  wrote:
>> After a user enters information in the box that follows (read), a program 
>> prints progress lines until a task is complete. The entry box remains until 
>> the program finishes; it floats downward with the latest line.
>> 
>> Is it possible to make the box disappear after the data entry is complete?
>> 
>> rac
>> 
>> 
>> _
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/users
>> 

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


Re: [racket] DrRacket needs work

2011-11-14 Thread Richard Cleis
The example can be simpler; typing a square bracket in a blank definitions 
window makes a single paren. The hotkey still makes a pair, though.

I wish I knew about this automatic paren stuff. I have been wearing out my 
esc-key.

rac

On Nov 14, 2011, at 6:58 AM, Sam Tobin-Hochstadt wrote:

> This may be a bad interaction between the automatic parens and the
> automatic paren adjustment, which puts in the right kind of paren in
> the right place.
> 
> Robby, do you know what's going on here?
> 
> On Mon, Nov 14, 2011 at 8:49 AM, Eric Tanter  wrote:
>> Here is what I did:
>> 
>> - activate the automatic parentheses option
>> 
>>  then:
>> 
>> type `('
>> --> ()
>> 
>> type `let ('
>> --> (let ())
>> 
>> type `['
>> --> (let ([))
>> 
>> Here I would have expected
>> --> (let ([]))
>> 
>> ?
>> 
>> -- Éric
>> 
>> 
>> On Nov 14, 2011, at 10:10 AM, Sam Tobin-Hochstadt wrote:
>> 
>>> They have successfully inserted thousands of square brackets for me.
>>> :)  What are you doing that doesn't work?
>>> 
>>> On Mon, Nov 14, 2011 at 6:06 AM, Eric Tanter  wrote:
 Nice!
 
 but automatic parentheses does not seem to work with square brackets.
 
 -- Éric
 
 
 On Nov 13, 2011, at 10:42 AM, Robby Findler wrote:
 
> Thanks for the suggestions. One minor observation below.
> 
> On Sun, Nov 13, 2011 at 4:50 AM, Tomi Neste  wrote:
>> - Paredit like editing functions, I can't personally use an editor
>> without these anymore. Again, this is something that could be hacked
>> up easily in Emacs but with DrRacket I have no idea where to start.
> 
> 
> I think you want to open the preferences dialog, go to the Editing
> pane, General subpane, and click "Enable automatic parentheses".
> 
> Robby
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
> 
 
 
 _
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
 
>>> 
>>> 
>>> 
>>> --
>>> sam th
>>> sa...@ccs.neu.edu
>>> 
>> 
>> 
> 
> 
> 
> -- 
> sam th
> sa...@ccs.neu.edu
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users


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


Re: [racket] Units/measures library

2011-11-17 Thread Richard Cleis
I vaguely remember seeing a Frink paper at LL4 (lightweight Languages 4). I 
think it even works.

It would be nice to be able to do something like:

(define-km d-km ...)
(define-ft d-ft ...) 
(define-secs t-secs ...) 
etc.

then be able to use functions like

(f-of-dees-and-t  v-km d-ft t-secs) where the units of the args don't matter. 
That seems TRish. For efficiency, blatant conversion functions are needed... or 
maybe a smart compiler. 

I think a billion-dollar Mars craft was lost over stuff like this.

rac

On Nov 17, 2011, at 8:10 AM, Matthias Felleisen wrote:

> 
> On Nov 17, 2011, at 8:41 AM, Jos Koot wrote:
> 
>> That should not be too difficult. I think of:
>> 
>> Temperatures: Celcius, Fharenheit, Kelvin
>> Distance: Meters, kilometers, land miles, nautic miles, lightyear nand so
>> on.
>> Mass: grams, kilograms, tons, slugs, and so on.
>> Weight: grams, kilograms, ounces, pounds, and so on.
>> Force: Newton, dyne, etc.
>> Energy: Joule, Erg, etc.
>> May be more.
>> 
>> This is easy to do.
>> Most work will be looking up references to physical units.
>> If no such library exists, I am willing to prepare a function like:
>> (unit-conversion from-unit to-unit from-number) -> to-number
>> Where from-unit and to-unit are two symbols naming units of the same
>> physical dimension.
> 
> 
> You may actually consider consuming real names instead of symbols 
> so that people can write expressions such as 
> 
> (convert 1/2 m ft)
> (convert 212 f c)
> (convert (sqrt i) g on) ; (I don't know the abbreviation for ounce)
> 
> -- Matthias
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


Re: [racket] In rkt or scheme, is there way to refer to the value of last expression?

2011-12-12 Thread Richard Cleis
I was thinking that a person mailing from 'fundingmatters' is asking a more 
practical question, for which 'compose' is the answer :O)

#lang racket/base

(define some-list '(1 2 3))
(define proc-1 +)
(define proc-2 sqrt)
(define (proc-n v) (* v 10))

(define f (compose proc-n proc-2 proc-1))

(apply f some-list)

rac



On Dec 12, 2011, at 5:08 PM, Danny Yoo wrote:

>> Just for the readability, is it possible to write
>> 
>> some-list
>> (proc-1 some-list)
>> (proc-2 (val-of-last-expression))
>> ...
>> (proc-n (val-of-last-expression)) ;where n is 'largeish'
>> 
>> instead of
>> 
>> (proc-n ... (proc-2 (proc-1 some-list
> 
> 
> Possible.  The syntax in Racket is programmable enough that adding it
> to the language isn't so bad.
> 
> 
> Let's say that we'd like to extend Racket's syntax so that it supports
> a (begin/it ...) form that acts like begin, but it also binds the
> value of the last expression.  How do we do this?
> 
> 
> First, let's reserve the name "it" the value of the very last
> expression.  We can create a context-sensitive keyword by using
> define-syntax-parameter:
> 
> ;;
> (define-syntax-parameter it
>  (lambda (stx)
>(raise-syntax-error #f "it should be used only in the context of a
> begin/it" stx)))
> ;;
> 
> We'll have it so if we use 'it' by accident, then it'll raise a syntax
> error with the right source location error.
> 
> Next, we can introduce a begin/it form that works like begin, except
> that it binds intermediate results:
> 
> ;
> (define-syntax (begin/it stx)
>  (syntax-case stx ()
>[(_ b)
> #'b]
> 
>[(_ b b-rest ...)
> (syntax/loc stx
>   (let ([b-val b])
> (syntax-parameterize ([it
>(make-rename-transformer #'b-val)])
>   (begin/it b-rest ...]))
> ;;;
> 
> 
> 
> Here's the complete source, with an example of its use:
> 
> ;;;
> #lang racket/base
> 
> (require (for-syntax racket/base)
> racket/stxparam)
> 
> (define-syntax-parameter it
>  (lambda (stx)
>(raise-syntax-error #f "it should be used only in the context of a
> begin/it" stx)))
> 
> (define-syntax (begin/it stx)
>  (syntax-case stx ()
>[(_ b)
> #'b]
>[(_ b b-rest ...)
> (syntax/loc stx
>   (let ([b-val b])
> (syntax-parameterize ([it
>(make-rename-transformer #'b-val)])
>   (begin/it b-rest ...]))
> 
> 
> (define (f x)
>  (* x x))
> (define (g x) (* x x x))
> 
> 
> ;; Exercise:
> (begin/it
>  (+ 1 2)
>  (f it)  ;; ... Um, didn't mean to swear there.
>  (g it))
> 
> (g (f (+ 1 2)))
> ;;;
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


Re: [racket] FW: Racket documentation for web development is just awful!

2011-12-19 Thread Richard Cleis

On Dec 19, 2011, at 6:03 PM, Gerry Weaver wrote:

> Hi Noob,
> 
> I believe I mentioned before that I had some trouble with the web development 
> docs myself. However, after thinking it over a bit, I decided to invest more 
> time in learning the language. It occurred to me that in order to really take 
> advantage of the web server, I would need to become a lot more familiar with 
> the advanced language concepts it is based on.

Half the people I deal with argue that they don't want to use Racket because it 
is not advanced enough; the other half argue that it is too advanced. I am 
forever trying to interpret these observations without drawing pessimistic 
conclusions.

> I'm finding that as I gain knowledge and experience, my ability to understand 
> the docs improves. The point I'm trying to make here is that without the 
> language foundation, it is just magical code. This is true with or without a 
> beginners guide. I would actually vote for a more thorough treatment of the 
> language itself documentation wise.

I feel more informed by the Racket group than any other, despite the subject of 
this thread. I use Racket partly because The Racket Guide is so good; it is 
even interesting to read. The Racket Reference has the remainder of the details 
required for completing software that pays the bills. Those two sources are the 
fish, and the often mentioned Racket-oriented texts are for learning how to 
fish. I admit that I don't do web programming, so I have no opinion of the web 
docs.

> How would one hope to use a continuation based server effectively without a 
> thorough understanding continuations? Isn't it these advanced language 
> features that attracted us to Racket/Scheme in the first place? At this point 
> in time, I'm not completely sure the additional web server docs wouldn't just 
> serve to short circuit the language learning process. Many thanks for the 
> patience of those who waited for me to realize this ;-)
> 
> I think Neil makes an interesting point. It seems like Racket would appeal 
> more to systems programmers coming from languages like C/C++ than it would to 
> the Java/Python/Ruby/PHP/Perl/etc. crowd. Racket in general has a much higher 
> price of entry than your average scripting language.

I don't agree. Racket could be taught in a manner which leads to programming 
like typical programmers in those other languages you mention. The apparently 
higher price of entry is for programming in better ways. Programmers in my lab 
occasionally admit that they wrote something in Racket, but actually wrote it 
like they would in their normal language. The price of entry for that is within 
the deviation of any of those languages.

> I mean no offense to web developers. I just think Racket/Scheme requires 
> quite a bit more effort and commitment than most would be willing to make.
> 

I find that the programming community is loaded with people who work hard, but 
don't want to learn more. To them, Racket is like cod liver oil in a soda 
shoppe.

Have as much fun as I do! ... and note that cod liver oil has vitamins, but 
soda is bad for your teeth.

rac

> Thanks,
> Gerry
> 
> 
> 
> -Original Message-
> From: "Racket Noob" 
> To: users@racket-lang.org
> Date: 12/19/11 17:37
> Subject: [racket] FW: Racket documentation for web development is just awful!
> 
>  
> 
> Of course I care! 
> I love racket and deeply respect all of you . But , I'm afraid that if you go 
> this way , Racket remain just another never used " academic " language . 
>   
> Community is too hermetic and self-sufficient . L et's take only RacketCon's 
> videos as example: you, boys are so much in your own world that you do not 
> realize how important it was to publish them on time . 
>  
>  
> Subject: Re: [racket] Racket documentation for web development is just awful! 
> From: matth...@ccs.neu.edu 
> Date: Mon, 19 Dec 2011 17:38:00 -0500 
> CC: users@racket-lang.org 
> To: racketn...@hotmail.com 
> 
>  
>  
> Is your goal to turn off every single core and non-core member on this list? 
> Or do you actually care?  
> 
>  
> 
>  
>  
>  
>  
>  
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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

Re: [racket] formlets with radio button & checkbox example?

2011-12-26 Thread Richard Cleis

On Dec 26, 2011, at 4:58 AM, Racket Noob wrote:

> 
> 
> From: racketn...@hotmail.com
> To: keyd...@gmx.de
> Subject: RE: [racket] formlets with radio button & checkbox example?
> Date: Mon, 26 Dec 2011 12:48:57 +0100
> 
> 
> No, you are not dumb. It's only that Racket web documentation sucks. But 
> never mind: there is also a Ruby on Rails, or maybe Django - bot excellent 
> web frameworks. They at least have good documentation and less eccentric and 
> more helpful community -- a community that does not only care for mass 
> production of always the same academic papers! 

You could make an example with less effort than required for your mass 
production of criticism. :O)

rac


> 
> > From: keyd...@gmx.de
> > Date: Sun, 25 Dec 2011 18:53:45 +0100
> > To: users@racket-lang.org
> > Subject: [racket] formlets with radio button & checkbox example?
> > 
> > Hi all,
> > 
> > could someone perhaps point me to a simple formlet example including not 
> > just text inputs, but also radio buttons and check boxes?
> > From the formlet syntax shown in Continue and the Formlets chapter, 
> > unfortunately I have problems understanding how the syntax for radio 
> > buttons and check boxes works, especially how to get back the values (that 
> > is, how to construct the second argument to formlet, for use by 
> > formlet-process).
> > 
> > (Sorry for the dumb question, but I have so much less time for Racket than 
> > I'd like to, and so I sometimes have problems understanding / inferring 
> > from the documentation...)
> > 
> > Many thanks in advance!
> > Sigrid
> > 
> > 
> > 
> > Racket Users list:
> > http://lists.racket-lang.org/users
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Racket / Scheme access to serial port, rs232, uart

2011-12-26 Thread Richard Cleis
About five years ago, I wrote simple C extensions that our group has used on OS 
X, Linux, and Windows. Today, I'd probably use the Foreign Function Interface. 
Sometimes we used the KeySpan USB-Serial hardware with the same extension. It 
might be possible to do what you show below entirely in Racket, but the serial 
interfaces are sometimes quirky enough that a small, non comprehensive C 
library is easier to maintain.

rac

On Dec 23, 2011, at 9:05 AM, Andrej Mošať wrote:

> I was wondering how can one access serial port from scheme / racket?
> To justify this ancient technology, more and more embedded devices,
> microcontrollers and development boards are being used. UART, rs232,
> serial over USB are being used to communicate with the devices.
> There is some support in several OS by a few programming languages.
> 
> Question: how can one reliably read / write to serial port from racket
> under windows and linux ?
> 
> Here are just some experiences.
> 
> Sofar, Python has pyserial - works as a charm within minutes,
> PERL claims to support rs232,
> C++ and C have libraries, which vary by OS and are not standardized,
> POSIX C++ seems to require the least amount of time to setup among
> those.
> 
> Linux can access serial port from command line by coreutils "stty"
> program, as found in
> http://planet.plt-scheme.org/package-source/xtofs/firmata.plt/1/0/
> i.e.
> 
> (define port-name "/dev/ttyS0")
> (system (string-append  "stty -f " port-name " 57600 cs8 cread clocal")
> 
> 
> Windows can directly read and write to serial ports  by using mode and
> reading / writing by copy,
> here is a basic code example to do it from racket:
> 
> #lang racket
> ;c:\Program Files (x86)\GnuWin32\bin>mode com3: baud=115200 parity=N
> data=8 stop=1
> ;copy com3 con
> 
> (define port-name "com3") ;;serial port
> (define baudrate 115200) ;;baud rate for port-name
> 
> ;;; 1. set device parameters
> ;; windows
> (when (eq? (system-type 'os) 'windows)
>  (if (system (string-append "mode " port-name ":")) ;; detect if
> device connected
>  (if (not (system (string-append  "mode " port-name ": baud="
> (number->string baudrate) "parity=N data=8 stop=1")) ;; set the baud
> rate and other params
>   )
>  (error "Failed to open the connection with " port-name "
> verify if your device is plugged in correctly") ;;error if device not
> connected
>  'OK_Baudrate_Set)
>  (error "Failed to open the connection with " port-name " verify
> if your device is plugged in correctly") ;;error if device not
> connected
>  )
>  )
> 
> 
> Thank you very much for your thoughts and comments.
> mosi
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users



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


Re: [racket] Beginner: advice COM port I/O

2011-12-30 Thread Richard Cleis

I'm not near a Winbox, so I can't try it. Normally, though, I loop the tx to 
the rx to ensure that the port can read what it writes.  Looping back normally 
involves little more than connecting pins 2 & 3 on the D-connector, if that is 
what you are using. 

I would also be wary of the terminator character being sent by displayln; the 
meter might care about the difference between newline, linefeed, and carriage 
return.

Unicode may be an issue here, too. You might need to use (string->bytes/utf-8  
"V00"). You can look at the signal on an oscilloscope to see if only four 
characters are being sent at the rate required by the meter.

rac 

On Dec 30, 2011, at 2:59 PM, Gilbert Martinez wrote:

> I've been experimenting with Racket v5.2 and a GW Instek 8212 meter connected 
> to my PC via COM1 (running WinXP SP3).
> 
> The meter responds to simple commands (e.g., "V00"  terminated with a line 
> feed is read voltage) and I've written simple programs in Python, VB, and 
> even QuickBasic  to query the device.
> 
> However, I've had no success in getting the device to respond from inside the 
> Racket REPL.
> 
> I've pasted the code I'm using below:
> 
> #lang racket
> 
> (let*-values 
> (((in out) (open-input-output-file "COM1"  #:mode 'binary)))
>   (displayln "V00" out)
>   (printf "~C~a~n" #\tab (read-bytes 1 in))
>   (close-input-port in)
>   (close-output-port out)) 
> 
> 
> Running from the interpreter just gives me the output below:
>   
> #
> > 
> 
> A tester in-line with the serial cable shows I am actually writing to the 
> port (I see a square-wave signal), so I know that I am at least writing to 
> the port. 
> 
> Any hints or pointers would be appreciated.
> 


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


Re: [racket] Teach yourself Racket in Fixnum Days?

2012-01-05 Thread Richard Cleis
Have you seen the tutorials? ...

Quick:An Introduction to Racket with Pictures
Continue: Web Applications in Racket
More: Systems Programming with Racket

rac



On Jan 5, 2012, at 7:51 PM, Giuseppe Paleologo wrote:

> I am a new Racket user. I am reading the Racket Guide, but I was wondering if 
> a shorter guide is available somewhere, perhaps not as comprehensive. 
> Something like "Teach yourself Racket in Fixnum Days?" or "Core Racket", 
> "Racket: the good parts" [I know, all Racket parts are good].  If not, I'll 
> keep reading the Guide. 
> 
> A bit of personal information, which could be of interest to identify the 
> potential Racket demographics. Currently I am using mostly R, but have used 
> at least a half dozen languages. Racket is particularly attractive for being 
> an elegant LISP like Scheme, but with batteries included (language 
> extensions, libraries), an active community, a passionate development team 
> and even an IDE.
> 
> Thanks,
> 
> -gappy
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Need help with macro...

2012-02-12 Thread Richard Cleis
The DrRacket interactions window replies with 48, not an error, when your 
syntax is defined in the definitions window, your function is defined in the 
interactions area, and the example is finally run in the interactions area. 

How are you making it fail?

Also, have you attempted to use the Macro Stepper? Even if you aren't actually 
debugging the macro, it coerces you to organize your thoughts about how your 
code is organized (in this case, how the expansion relates to the word 'mult' 
and it's actual definition.)

rac
 

 
On Feb 12, 2012, at 11:30 AM, FS Racket wrote:

> I'm trying to write a macro that where the pre-transformation form is:
> 
> (==> exp1 exp2 ... expn)
> 
> and where exp2 through expression expn are sexps that contain a '_' 
> placeholder.  The idea is that starting with exp2, the _ gets replaced with 
> the previous expression.  For example:
> 
> (==> 12 (+ _ 2) (* 3 _))  would become  (* 3 (+ 12 2)).
> 
> I've written a couple of different versions that exhibit the same problem 
> (described later).  Here's my most recent attempt:
> 
> (define-syntax ==>
>   (lambda (stx)
> (define (replace-in-first exp-list new-val)
>   (let* ([new-exp 
>   (map (λ (x) 
>  (if (eq? x '_)
>  new-val
>  x))
>(syntax->datum (car exp-list))) ]
>  [new-stx (datum->syntax stx new-exp )] )
> (cons new-stx (cdr exp-list)) ))
>
> (syntax-case stx ()
>   [(_ exp) #'exp]
>   [(_ exp1 exp2 ...)
>   
>(with-syntax ([(threaded-exp ...)
>   (replace-in-first (syntax->list #'(exp2 ...)) #'exp1)])
>  #'(==> threaded-exp ...))] )))
> 
> The problem I'm experiencing is best demonstrated with examples.  First, 
> assume the following definition exists in the source file:
> 
> (define (mult x y) (* x y))
> 
> ;;;EXAMPLES
> (==> (+ 2 2)
>  (+ 4 _)
>  (+ _ 5))   ;; works fine; result is 13
> 
> (==> 
>  (mult 3 4)
>  (mult _ 2))  ;; works fine; result is 24
> 
> (==>
>  13
>  (mult _ 2)
>  (+ 12 _)) ;; works fine; result is 38
> 
> (==>
>  (mult 12 2)
>  (mult 2 _)
>  (mult _ 1))  ;; FAILS withs error: "expand: unbound identifier in module in: 
> mult"
> 
> So far as I can tell, the macro fails with this error when the number of 
> expressions is greater than 2 and when the sexps contain 2 or more references 
> to a user-defined function.  I'm guessing that somehow the macro fails to 
> provide appropriate lexical context for the subsequent calls to the 
> user-defined function (or something like that) but I'm stumped.  Any ideas?
> 
> Thanks.
> 
> 
> 
> 
> 
>   
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



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


Re: [racket] Need help with macro...

2012-02-12 Thread Richard Cleis
On Feb 12, 2012, at 1:09 PM, FS Racket wrote:

> 
> 
> On Sun, Feb 12, 2012 at 1:34 PM, Richard Cleis  wrote:
> The DrRacket interactions window replies with 48, not an error, when your 
> syntax is defined in the definitions window, your function is defined in the 
> interactions area, and the example is finally run in the interactions area.
> 
> How are you making it fail?
> 
> Also, have you attempted to use the Macro Stepper? Even if you aren't 
> actually debugging the macro, it coerces you to organize your thoughts about 
> how your code is organized (in this case, how the expansion relates to the 
> word 'mult' and it's actual definition.)
> 
> rac
> 
> 
> Hi Richard,
> 
> Good questions.
> 
> The way my code is organized is that the macro is in its own file and 
> installed as a collection in my personal library (i.e. the default location 
> of personal collections).  I then create a new file, say "test.rkt", require 
> the macro library file, and then define the function "mult".  Within this 
> same file, I then add the code examples contained in my previous email.  
> Finally, I "run" the "test.rkt" file using the "Racket -> Run" menu option.
> 
> Yes, I have used the macro stepper; I should have mentioned that.  It's 
> bizarre.  Prior to any expansion, all identifiers named 'mult' have an 
> associated binding.  As I step through the expansion in the following code, 
> the last 'mult' eventually loses its binding.  I don't know how or why.  
> 
> (==>
>  (mult 12 2)
>  (mult 2 _)
>  (mult _ 1))
> 
> Please let me know if any further clarification is needed.

In the example that doesn't work, the first mult is needed for another use of 
==>. In the simpler examples, it is not. Notice that the orphaned mult occurs 
on the second step when another use is expanded, while in the simpler examples 
another use of ==> does not occur.  In the simple cases, mult is known to the 
expanded code; in the example that doesn't work, mult is not known to repeated 
use of the macro. Another clue is: if you run the test in the interactions 
window, it works because the definition of mult (in definitions) is 
automatically provided for interactions.

I haven't even read your macro; the amazing and amusing macro stepper knows all 
and tells all.

rac



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


Re: [racket] Need help with macro...

2012-02-12 Thread Richard Cleis

On Feb 12, 2012, at 2:53 PM, FS Racket wrote:

> In the example that doesn't work, the first mult is needed for another use of 
> ==>. In the simpler examples, it is not. Notice that the orphaned mult occurs 
> on the second step when another use is expanded, while in the simpler 
> examples another use of ==> does not occur.  In the simple cases, mult is 
> known to the expanded code; in the example that doesn't work, mult is not 
> known to repeated use of the macro. Another clue is: if you run the test in 
> the interactions window, it works because the definition of mult (in 
> definitions) is automatically provided for interactions.
> 
> I haven't even read your macro; the amazing and amusing macro stepper knows 
> all and tells all.
> 
> 
> Your comment caused me to think about why the repeated calls to ==> would 
> 'mult' to become "unknown".  Eventually, I realized that the syntax->datum 
> call was probably doing too much; i.e. it was stripping away too much 
> information so when I built back up the new expression, the binding of 'mult' 
> was lost.  
> 
> At least, that's my guess.  I think the Racket documentation is fantastic but 
> I find a bit of experimentation is necessary to figure some things out and 
> that's what I've come up with.  (Perhaps an experience macrologist can 
> comment?).  
> 
> Anyhow, here's a version that works (er...at least it seems to work so 
> far...):
> 
> (define-syntax ==>
>   (lambda (stx)
> (define (replace-in-first exp-list new-val)
>   (let* ([new-exp 
>   (map (λ (x) 
>  (if (eq? (syntax-e x) '_)
>  new-val
>  x))
>(syntax->list (car exp-list))) ]

It's nice to make the macro processor do the work for you. In Matthias 
Felleisen's example, 'it' is born in the environment of the program, then the 
macro uses that same 'it' for the 'let' assignment and the arguments in the 
supplied expressions. Your macro requires more writing because it doesn't take 
advantage of such scope control and it doesn't use ellipses to form the loop.

I'm reading the macro chapter in the guide now (totally coincidentally), so I 
am curious to find out if there is a new way to write syntax-rules for the 
cases for which they have worked so well in the past.

rac  


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


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


Re: [racket] Racket style question

2012-03-21 Thread Richard Cleis
FWIW:

I believe the style guide suggests that 'cond' should be used instead of 'if' 
when a clause requires more than one expression. The newer Racket versions of 
'cond' also permit internal defines. 'Begin' is unnecessary.

rac



On Mar 21, 2012, at 3:37 PM, Joe Gilray wrote:

> Hi Rodolfo,
> 
> In this case though, printf will never return #f so "and" is equivalent to 
> "begin", right?
> 
> -Joe
> 
> 
> 
> On Wed, Mar 21, 2012 at 2:30 PM, Rodolfo Carvalho  
> wrote:
> On Wed, Mar 21, 2012 at 17:21, Joe Gilray  wrote:
> Hi Tim,
> 
> Thanks for sharing your code.
> 
> Quick, newby question: why do you use "and" instead of "begin" in your 
> progress function?
> 
> 
> If you are used to run commands from bash you may do things like
> 
> command1 && command2 && command3
> 
> e.g.:  mkdir somedir && cd somedir && git clone ...
> 
> 
> Why people do that? Simply put, all of the commands after a `&&' are only run 
> if the commands before executes fine (return code 0).
> So "git clone" will be executed only if I could create a dir and cd to it. It 
> will not be executed if I don't have permissions to create a dir.
> 
> Using "and" is like using "&&" in bash, while "begin" is equivalent of 
> separating the commands with ";".
> 
> More on short-circuit evaluation: 
> http://en.wikipedia.org/wiki/Short-circuit_evaluation
> 
> HTH,
> 
> Rodolfo
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Looping with look-behind and look-forward

2012-05-27 Thread Richard Cleis
If you are only using integers, efficiency matters, and your running averages 
are larger than two (I can't tell of you are using three for a simple example, 
or if that is the only requirement), then it might be better to maintain the 
latest sum by subtracting the oldest member and adding the newest. If the 
processing time for the arithmetic is much smaller than the overhead of list 
maintenance, then this post isn't very useful.

rac  


On May 27, 2012, at 9:54 AM, Harry Spier wrote:

> Sorry Jens, I see I've just recreated the form you originally suggested.
> Thanks, Harry
> 
> On Sun, May 27, 2012 at 11:46 AM, Harry Spier  
> wrote:
>> I think I've come up with a simpler form to do this.
>> 
>> (define (running-average-of-3 l)
>>   (for
>>( [prior (in-list l)]
>>  [x (in-list (rest l))]
>>  [next (in-list (rest (rest l)))])
>>   (displayln (/ (+ x prior next) 3
>> 
>> (running-average-of-3 '(1 2 3 4 5 6))
>> 
>> 
>> So I can do something like:
>> 
>> (define (f1 l)
>>   (for/fold ([result-list '()])
>>( [prior (in-list (append '() l))]
>>  [x (in-list l)]
>>  [next (in-list  (append (rest l) '()))])
>>...
>>... make new-result-element using x prior and next...
>>   (cons new-result-element result-list))
>>  (reverse result-list))
>> 
>> The list I'm working on in my application has about 40,000 sub-lists.
>> Will the compiler build new lists from scratch as the sequence for
>> prior and next in this code or will it use pointers to and from the
>> existing list l to do this?
>> 
>> Thanks,
>> Harry
>> 
>> On Sun, May 27, 2012 at 10:38 AM, Jens Axel Søgaard
>>  wrote:
>>> 2012/5/27 Harry Spier :
 Is the "for" form a macro?  And if so how difficult would it be to
 make a new form "for-with-look-around" that had built in look-back and
 look-ahead operators (next x) (prior x) (  next?) (prior?).
 
 So you could do something like:
 
 ((define (running-average-of-3 l)
   (for-with-look-around
([x (in-list l)])
(unless? (or (prior?) (next?))
 (displayln (/ (+ x (prior x) (next x)) 3))
 
 From a functional programming perspective is building a form like this
 a bad idea?
>>> 
>>> It is a fine idea.
>>> Here is variation on the idea.
>>> 
>>> (define (in-triples l)
>>>  (define (sublists xs)
>>>(if (empty? xs)
>>>'()
>>>(cons xs (sublists (rest xs)
>>>  (define (triple xs) (take xs 3))
>>>  (sequence-map triple (drop-right (sublists l) 2)))
>>> 
>>> (define (running-average-of-3 l)
>>>  (for ([t (in-triples l)])
>>>(match-define (list x y z) t)
>>>(displayln (/ (+ x y z) 3
>>> 
>>> (running-average-of-3 '(1 2 3 4 5 6))
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



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


Re: [racket] Congratulations to Shriram: Milner Young Researcher Award

2012-06-12 Thread Richard Cleis
Congratulations for being young, too!

RAC

On Jun 12, 2012, at 7:52 PM, Matthew Flatt  wrote:

> Shriram Krishnamurthi has been selected as the 2012 winner of the
> SIGPLAN Robin Milner Young Researcher Award!
> 
> The Milner Award is new this year, but with this year's precedent, it
> will surely prove to be the most prestigious SIGPLAN award that is
> possible for a researcher within their first 20 years. The award was
> announced minutes ago here at PLDI, and the award citation will soon
> appear at the following URL:
> 
> http://www.sigplan.org/award-milner.htm
> 
> Congratulations, Shriram!
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users

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


Re: [racket] how must I interpreted this exercise

2012-06-23 Thread Richard Cleis
You can print the result of the following, where the #t or #f is your value to 
be tested.

(string-append "It's" (if #t "" " not") " true.")
(string-append "It's" (if #f "" " not") " true.")

but I am not sure if that is what you are asking.

rac

On Jun 23, 2012, at 12:45 PM, Roelof Wobben wrote:

> I have another "problem" I try to solve in my head.
> 
> Suppose I want to change one word in a sentence depening if a comparision is 
> true or false.
> 
> I could do this in pseudo code.
> 
> if comparision is true then print "it's true" else  print "it's not true"
> 
> It works but I type two time's "it's true".
> 
> Can this be done so I have to type only one time the sentence and depeding on 
> true or false the word not is used. 
> 
> Roelof
> 
> 
> 
> Op 23-6-2012 16:18, Matthias Felleisen schreef:
>> 
>> Origin means (0,0) or plain 0 in English. 
>> 
>> 
>> On Jun 22, 2012, at 2:42 PM, Roelof Wobben wrote:
>> 
>>> Hello, 
>>> 
>>> I try to make this exercise : 
>>> 
>>> Exercise 76: A programmer has chosen to represent locations as Cartesian 
>>> points or just points:
>>> ; Location is one of:
>>> ; – Posn
>>> ; – Number
>>> ; interp. Posn are positions on the Cartesian grid,
>>> ; Numbers are positions on the number line
>>> Design the function in-reach, which determines whether or not a given 
>>> location’s distance to the origin is strictly less than some constantR.
>>> 
>>> So I must design a function called in-reach.
>>> 
>>> Am I right I need to use two structs (Posn) . One for the given location 
>>> and one for the origon ?
>>> 
>>> Regards, 
>>> 
>>> Roelof
>>> 
>>> 
>>> 
>>> 
>>>  Racket Users list:
>>>  http://lists.racket-lang.org/users
>> 
> 
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] how must I interpreted this exercise

2012-06-24 Thread Richard Cleis
Check-expect is used to test your function. 
Make that work first. 

Then you can use the design recipe to make a new function.

The new function will accept the output of your first function and return the 
message that you want… without any repeated words in the function.

rac

On Jun 24, 2012, at 1:43 PM, Roelof Wobben wrote:

> Hello, 
> 
> This soluation is not what I was looking for.
> And it uses list which I don't have learned so far.
> 
> So far I have this : 
> 
> ; constanten 
> 
> (define R 5)
> (define first_tekst "Het ingegeven punt")
> (define is_tekst "is")
> (define middle_tekst "dichtbij het 0 nulpunt")
> (define niet "niet")
> 
> 
> ;Number Number -> Number 
> ;This function calculates the distance of a given point compared to the origin
> (check-expect (calculate 1 0) 1)
> (check-expect (calculate 3 4) 5)
> (check-expect (calculate 0 3) 3)
> (define (calculate getal1 getal2)
>   (cond 
> [ (equal? getal1 0) getal2]
> [ (equal? getal2 0) getal1]
> [else (sqrt (+ (* getal1 getal1) (* getal2 getal2)))]
> ))
> 
> ; Struct -> String
> ; Function who outputs a string dependinh on the outcome of the calculation 
> of the distance to the origin
> (check-expect (is-near (make-s 1 0) "Het ingegeven punt is dichtbij het 
> nulpunt"))
> (check-expect (is-near (make-s 3 4) "Het ingeven punt is niet dichtbij het 
> nulpunt"))
> (define (is-near s r)
>   ( if (< (calculate (posn-x s) (posn-y s)) r)  
>   
> 
> Now I can do  (string append  first_tekst is middle-tekst) and (string-append 
> first-tekst  is niet middle-tekst)  but then I do almost two times the same 
> with one difference the niet part.
> And Im looking for a better solution.
> 


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


Re: [racket] how must I interpreted this exercise

2012-06-25 Thread Richard Cleis
That is-near a better solution ;o) 

I think HtDP has problems that require assembling sentences from different 
parts of speech. That is a very challenging software field.

rac
 


On Jun 25, 2012, at 12:41 AM, Roelof Wobben wrote:

> You mean something like this :
> 
> (check-expect (calculate 0 3) 3)
> (define (calculate getal1 getal2)
>  (cond
>[ (equal? getal1 0) getal2]
>[ (equal? getal2 0) getal1]
>[else (sqrt (+ (* getal1 getal1) (* getal2 getal2)))]
>))
> 
> ; String -> String
> ; This function produces a string depending on the input "niet " or ""
> (check-expect (afdrukken "") "Het ingegeven punt is dichtbij het 0 punt")
> (check-expect (afdrukken "niet ") "Het ingegeven punt is niet dichtbij het 0 
> punt")
> (define (afdrukken s)
>  (string-append first_tekst s middle_tekst)
>  )
> 
> 
> ; Struct -> String
> ; Function who outputs "niet" or a empty string depending on the calculated 
> distance compared with R.
> (check-expect (is-near (make-posn 1 0) 5) "Het ingegeven punt is dichtbij het 
> 0 punt")
> (check-expect (is-near (make-posn 3 4)  5) "Het ingegeven punt is niet 
> dichtbij het 0 punt")
> (define (is-near s r)
>  ( if (< (calculate (posn-x s) (posn-y s)) r) (afdrukken "") (afdrukken "niet 
> ")
>   ))
> 
> 
> Roelof
> 
> 
> 
> Op 25-6-2012 6:18, Richard Cleis schreef:
>> Check-expect is used to test your function.
>> Make that work first.
>> 
>> Then you can use the design recipe to make a new function.
>> 
>> The new function will accept the output of your first function and return 
>> the message that you want… without any repeated words in the function.
>> 
>> rac
>> 
>> On Jun 24, 2012, at 1:43 PM, Roelof Wobben wrote:
>> 
>>> Hello,
>>> 
>>> This soluation is not what I was looking for.
>>> And it uses list which I don't have learned so far.
>>> 
>>> So far I have this :
>>> 
>>> ; constanten
>>> 
>>> (define R 5)
>>> (define first_tekst "Het ingegeven punt")
>>> (define is_tekst "is")
>>> (define middle_tekst "dichtbij het 0 nulpunt")
>>> (define niet "niet")
>>> 
>>> 
>>> ;Number Number -> Number
>>> ;This function calculates the distance of a given point compared to the 
>>> origin
>>> (check-expect (calculate 1 0) 1)
>>> (check-expect (calculate 3 4) 5)
>>> (check-expect (calculate 0 3) 3)
>>> (define (calculate getal1 getal2)
>>>   (cond
>>> [ (equal? getal1 0) getal2]
>>> [ (equal? getal2 0) getal1]
>>> [else (sqrt (+ (* getal1 getal1) (* getal2 getal2)))]
>>> ))
>>> 
>>> ; Struct -> String
>>> ; Function who outputs a string dependinh on the outcome of the calculation 
>>> of the distance to the origin
>>> (check-expect (is-near (make-s 1 0) "Het ingegeven punt is dichtbij het 
>>> nulpunt"))
>>> (check-expect (is-near (make-s 3 4) "Het ingeven punt is niet dichtbij het 
>>> nulpunt"))
>>> (define (is-near s r)
>>>   ( if (< (calculate (posn-x s) (posn-y s)) r)
>>>   
>>> Now I can do  (string append  first_tekst is middle-tekst) and 
>>> (string-append first-tekst  is niet middle-tekst)  but then I do almost two 
>>> times the same with one difference the niet part.
>>> And Im looking for a better solution.
>>> 
> 
> 



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


Re: [racket] Running Racket in the R6RS mode

2012-07-14 Thread Richard Cleis

On Jul 14, 2012, at 6:54 PM, Rouben Rostamian wrote:

> Thank you, Matthias (and also Neil Van Dyke) for the very
> detailed explanation of the design decisions that has gone
> into Racket.  Now I see that Racket is intended to be a Lisp
> dialect of its own rather than a "Scheme plus extensions"
> as I had mistakenly assumed.
> 
> In retrospect, that assumption was influenced by my experience
> with C which is the predominant language in which I program.
> Various implementations of C, such as those of GNU, Microsoft,
> Intel, Sun, AIX, etc., provide their own diverse extensions
> to the language but in all cases the extensions are strict
> supersets of the standard C -- they would be considered
> unacceptable otherwise.
> 
> I was looking for something similar in the scheme world but
> what I have learned is that one cannot extend his experience
> from one programming language realm and culture into another
> and expect to find a one to one correspondence.

The 'one to one correspondence' to which you refer are the implementation of 
expressions and fundamental functions. I believe they are as significant as the 
standard upon which C is based. 

The recent discussion entitled "This is too clumsy. Is there a better way?" had 
several examples which are common to modern Schemes.  R5RS and Racket both 
accept the following expressions and functions, even though the implementations 
are separated by two decades.

(define (all-lower-case? locs)
  (if (null? locs) #t
  (if (char-upper-case? (car locs)) #f
  (all-lower-case? (cdr locs)

(all-lower-case? (string->list "asdf12#@"))
(all-lower-case? (string->list "asDf12#@"))

I am a longtime C programmer that is more worried about maintaining C than 
porting Racket programs if the Racketeers all move to Mars.

rac


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


Re: [racket] Is eval very slow?

2012-07-19 Thread Richard Cleis
It's fun growing older with computers. In the days of 8085's, we were almost 
happy to call a subroutine or switch contexts for an interrupt in 20 
microseconds; my gosh, addresses and data must be pushed and popped and all of 
that stuff takes time.  The response earlier in this thread showed that an 
evaluation of a new expression, a much more considerable task, to be the same 
20 microseconds... but these days we consider this to be intolerably slow. :O)

rac

On Jul 19, 2012, at 5:53 AM, Matthias Felleisen wrote:

> 
> Here is a conjecture at a history-based interpretation. 
> 
> Lisp was eval and apply, and that was all there was to it, and calling eval 
> was dirt cheap -- compared to running code. 
> 
> Over the next few decades Lispers learned to "pre-process" Lisp, meaning a 
> lot of dynamic computation was moved to pre-eval time. At the same time, 
> Lispers learned that eval is evil in most cases and that it is often 
> replacable by something simple (like a case dispatch on the op position plus 
> apply). 
> 
> Other languages started being a "Lisp": perl, python, javascript. Instead of 
> learning from Lisp's history, they re-invented it -- starting from a cheap 
> eval cycle. Now eval is popular again. Perhaps this is even justified for 
> initial uses of something like JavaScript. You send some code, it is eval'ed 
> and the evaluation renders some "image" inside of a browser frame. Done. But 
> now we do so much more with this interactive script -- manage mail, play 
> games -- JavaScript needs to have a real compiler too. And as we get into 
> compilation, its eval will get slower and perhaps JS programmers will 
> re-learn what Lispers learned. 
> 
> But this won't be the end. I predict that in 20 years some other language 
> will re-invent eval and it will resume from there. 
> 
> CS, the science of reinvention. 
> 
> 
> 
> 
> 
> On Jul 19, 2012, at 3:46 AM, Eli Barzilay wrote:
> 
>> Just now, John Clements wrote:
>>> 
>>> I don't think you should be shocked; I believe that calls to eval
>>> are essentially triggering full passes of the parser and compiler,
>>> dynamically. It's true that you could optimize for certain special
>>> cases (such as yours), but generally speaking these use cases are
>>> rare, particularly since I'm guessing that the places where this
>>> optimization would be possible are also the places where eval isn't
>>> needed.
>> 
>> As a sidenote, this is not something that is unique to racket or that
>> is new in any way...  I first "encountered" this in 1995 in a project
>> written in Allegro Lisp -- I was surprised about how slow `eval' was,
>> and when I asked about it, the advice I was given is that in extreme
>> cases where you really need a fast evaluation of dynamically generated
>> code, you're better off writing a mini-evaluator instead.
>> 
>> (Another sidenote: there are some languages with a "very fast" eval,
>> like elisp and newlisp.  In these languages it can be as fast as
>> running normal code, but this is because there is little to no
>> compilation done.)
>> 
>> -- 
>> ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
>>   http://barzilay.org/   Maze is Life!
>> 
>> Racket Users list:
>> http://lists.racket-lang.org/users
> 
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


[racket] sequence-filter of in-port

2012-07-22 Thread Richard Cleis
I was attempting to use sequence-filter and in-port to filter large files into 
small lists, but the following error occurs on the occasion that everything is 
filtered: 

apply: expects type  as 2nd argument, given: #f; other arguments 
were: #

;; equivalent arbitrary examples (I think)

(define (might-filter-all x) (= x 99))  ; both cases below return '(3), if 99 
is changed to 3

(sequence->list (sequence-filter might-filter-all (in-range 3 4)))  
   ; returns '()
(sequence->list (sequence-filter might-filter-all (in-port read 
(open-input-string "3" ; an error

I could not find in-port in sequence.rkt, so I did not read it.

Should the in-port sequence be different?

rac


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


Re: [racket] sequence-filter of in-port

2012-07-22 Thread Richard Cleis
5.2.

Looks like it has been fixed. Thanks for checking.

RAC

On Jul 22, 2012, at 10:57 AM, Adolfo Pérez Álvarez  wrote:

> Hi Richard,
> 
> What version of Racket are you using? I've tested your code with
> 5.3.0.16 and it worked as expected, returning '() in both cases.
> 
> 2012/7/22 Richard Cleis :
>> I was attempting to use sequence-filter and in-port to filter large files 
>> into small lists, but the following error occurs on the occasion that 
>> everything is filtered:
>> 
>> apply: expects type  as 2nd argument, given: #f; other 
>> arguments were: #
>> 
>> ;; equivalent arbitrary examples (I think)
>> 
>> (define (might-filter-all x) (= x 99))  ; both cases below return '(3), if 
>> 99 is changed to 3
>> 
>> (sequence->list (sequence-filter might-filter-all (in-range 3 4)))   
>>   ; returns '()
>> (sequence->list (sequence-filter might-filter-all (in-port read 
>> (open-input-string "3" ; an error
>> 
>> I could not find in-port in sequence.rkt, so I did not read it.
>> 
>> Should the in-port sequence be different?
>> 
>> rac
>> 
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users


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


Re: [racket] sequence-filter of in-port

2012-07-22 Thread Richard Cleis
I just downloaded 5.2.1. It works, too. I am slow to upgrade because I don't 
fix what ain't broke. That was broke, so I fixed it by upgrading. Now I have a 
better understanding of how sequences work, too.

rac

On Jul 22, 2012, at 10:57 AM, Adolfo Pérez Álvarez wrote:

> Hi Richard,
> 
> What version of Racket are you using? I've tested your code with
> 5.3.0.16 and it worked as expected, returning '() in both cases.
> 
> 2012/7/22 Richard Cleis :
>> I was attempting to use sequence-filter and in-port to filter large files 
>> into small lists, but the following error occurs on the occasion that 
>> everything is filtered:
>> 
>> apply: expects type  as 2nd argument, given: #f; other 
>> arguments were: #
>> 
>> ;; equivalent arbitrary examples (I think)
>> 
>> (define (might-filter-all x) (= x 99))  ; both cases below return '(3), if 
>> 99 is changed to 3
>> 
>> (sequence->list (sequence-filter might-filter-all (in-range 3 4)))   
>>   ; returns '()
>> (sequence->list (sequence-filter might-filter-all (in-port read 
>> (open-input-string "3" ; an error
>> 
>> I could not find in-port in sequence.rkt, so I did not read it.
>> 
>> Should the in-port sequence be different?
>> 
>> rac
>> 
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users



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


Re: [racket] newbie drracket usage questions

2012-07-30 Thread Richard Cleis

On Jul 30, 2012, at 10:53 PM, D Herring wrote:

> Hi,
> 
> How would one accomplish the following in DrRacket?
> 
> "apropos" (CL/shell) or "lookfor" (Matlab)
> Given a search string, return a list of symbols with matching name or 
> documentation.
> I found that XRepl has the ,apropos command; but I haven't figured out an 
> easy way to invoke it in DrRacket.

Do you mean: do that within Racket, or from Racket?

You can use the shell with (system "apropos ..."), but I don't know how useful 
that is for Racket docs.

Within Racket you can use the F1 key to get to the docs that tell you where a 
function lives. That 
opens a web browser that allows you to type strings for more searching (locally 
and not).

I fear I am telling you things that you already know. :O)

rac


> 
> 
> Finding the source of definitions.
> a la ctags or 
> http://common-lisp.net/project/slime/doc/html/Finding-definitions.html
> Given a function or global parameter, open the file that defined it and 
> scroll to the definition.
> I found documentation for storing source locations, but nothing on how to 
> query the information.
> 
> 
> Thanks,
> Daniel
> 
> 
> Racket Users list:
> http://lists.racket-lang.org/users


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


Re: [racket] We need volunteers to test WeScheme!

2012-08-08 Thread Richard Cleis
Hey, that's slick. I like how it links all of the parts of

(map cons 1 2 3 4)

with 

map: expects a list as 2nd argument, but given: 1; other arguments were: 
# 2 3 4

[I'm unsure if the colored formatting will show up on the list]

rac [Lion Safari]



On Aug 8, 2012, at 1:29 PM, Danny Yoo wrote:

> We have revamped the error reporting infrastructure in WeScheme.  In
> particular, we've [1] implemented the color-coding proposal proposed
> by Guillaume Marceau et al [2].  We are looking for volunteers to hit
> our test site and let us know if  they see strange output from the
> colored error highlighting.
> 
> Please visit:
> 
>http://dyoo-test.appspot.com
> 
> and try snippets of code that should produce errors.
> 
> 
> For a few examples:
> 
>(cond)
> 
>;;;
> 
>(define (f x) (* x x))
>(f)
>(f 3 4 5)
> 
>;;;
>(/ 1 2 3 (- 1 1))
> 
> 
> You should see colored highlighting for each one of these cases.  More
> generally:
> 
>* The referents in syntax errors should color highlight where
> appropriate.  Clicking on the colored links should focus their
> location in the definitions window.
> 
>* Certain runtime errors, such as procedure arity mismatch, should
> highlight the affected arguments at runtime.  Others include division
> by zero and other type error checks.
> 
> 
> We'd appreciate your feedback and bug reports!
> 
> 
> ---
> 
> [1] By "we", I mean the following excellent folks:
> 
>* Michael Rowland
>* Andrew Tian
>* Daniel Kocoj
> 
> [2] 
> http://cs.brown.edu/~sk/Publications/Papers/Published/mfk-mind-lang-novice-inter-error-msg/
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Are there Racket structures similar to Common Lisp's?

2012-08-16 Thread Richard Cleis
Are you asking for stuff like this?

http://docs.racket-lang.org/reference/define-struct.html

rac

On Aug 16, 2012, at 10:09 PM, Rouben Rostamian wrote:

> Is there the equivalent of Common Lisp's /structure/ type in
> Racket?  I looked through Racket's User Guide and Reference
> manuals but did not see something similar, although it's
> quite possible that I saw one but did not recognize it.
> 
> Specifically, here is what I want.  Consider the Common Lips
> definition of a /person/ structure:
> 
> (defstruct person
>   name
>   age
>   waist-size
>   favorite-color)
> 
> Then create an instance:
> 
> (make-person :age 35
> :favorite-color "blue"
> :name "Bob")
> 
> The latter echos:
> 
>  #S(PERSON :NAME "Bob" :AGE 35 :WAIST-SIZE NIL :FAVORITE-COLOR "blue")
> 
> Let's note that the order of fields when invoking /make-person/
> need not be the same as the order in which the /person/
> structure is defined.
> 
> Furthermore, since /waist-size/ was not specified at invocation,
> it was assigned NIL.
> 
> -- 
> Rouben Rostamian
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] taking from a generator, and a possible bug

2012-08-18 Thread Richard Cleis
Are you looking for something like this?

(define (tr2 k n) (build-list k (lambda (x) (random n
;; the x arg is unused (it counts up)

rac



On Aug 18, 2012, at 10:59 PM, Ian Tegebo wrote:

> (define (call-n-times f n)
>(define (helper f n lst)
>  (if (< n 1)
>  lst
>  (helper f (- n 1) (cons (f) lst
>(helper f n '()))
> 
> (define (take-randoms k n)
>(call-n-times (curry random n) k))


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


Re: [racket] Newbie question: creating a custom canvas

2012-08-23 Thread Richard Cleis
I dont know enough about this stuff, other than to 'rather slavishly' follow 
your code and make it work. :O)

Try this:

...
   (define/override (on-paint) ; eliminate the argument
 (define dc (send this get-dc)) ; 'this' is the current instance
...

On Aug 23, 2012, at 6:29 PM, Gregory Woodhouse wrote:

> I apologize in advance for the elementary nature of this question, and for 
> the amount of code included below. I'm having a tough time following the 
> documentation for racket/gui and racket/draw. My first attempt to create a 
> Sudoku grid follows the example in the documentation rather slavishly and 
> works fine
> 
> 
> (define frame (new frame% [label "Sudoku"]
>   [width 300]
>   [height 300]))
> 
> (define grid-canvas (new canvas% [parent frame]
> [min-width 300]
> [min-height 300]
> [paint-callback
> (lambda (canvas dc)
>   (let
>   ([w (send canvas get-width)]
>[h (send canvas get-height)])
> (send dc set-pen "black" 3 'solid)
> (for ([i (in-range 3)])
>   (send dc draw-line 0 (* i (/ h 3)) w (* i (/ h 3)))
>   (send dc draw-line (* i (/ w 3)) 0 (* i (/ w 3)) h))
> (send dc set-pen "black" 1 'solid)
> (for ([i (in-range 9)])
>   (send dc draw-line 0 (* i (/ h 9)) w (* i (/ h 9
> (for ([i (in-range 9)])
>   (send dc draw-line (* i (/ w 9)) 0 (* i (/ w 9)) 
> h]))
> 
> ; Show the frame by calling its show method
> (send frame show #t)
> 
> 
> But this does not work
> 
> (define frame (new frame% [label "Sudoku"]
>   [width 300]
>   [height 300]))
> 
> (define grid-canvas%
>  (class canvas%
>(define/override (on-paint dc)
>  (let
>  ([w (send this get-width)]
>   [h (send this get-height)])
>(send dc set-pen "black" 3 'solid)
> (for ([i (in-range 3)])
>   (send dc draw-line 0 (* i (/ h 3)) w (* i (/ h 3)))
>   (send dc draw-line (* i (/ w 3)) 0 (* i (/ w 3)) h))
> (send dc set-pen "black" 1 'solid)
> (for ([i (in-range 9)])
>   (send dc draw-line 0 (* i (/ h 9)) w (* i (/ h 9
> (for ([i (in-range 9)])
>   (send dc draw-line (* i (/ w 9)) 0 (* i (/ w 9)) h
>(super-new)))
> 
> (define the-grid (new grid-canvas% [parent frame]
>   [min-width 300]
>   [min-height 300]))
> 
> 
> I get an arity mismatch in on-paint.
> 
> The reason for not wanting in to pass in the paint-callback is that I want to 
> be able to augment it somewhat in grid-canvas% (specifically, I need to draw 
> in the digits based on the contents of the grid!) It's not clear (to me) how 
> to do this, or if I should be taking an entirely different approach.
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] [plt-edu-talk] Does a Scheme procedure "return" a value?

2012-09-08 Thread Richard Cleis
I am writing documentation. What are acceptable words for the following 
brackets?

The function f [what verbs are ok?] a name, then [what about here?] a phone 
number.

rac



On Sep 8, 2012, at 9:07 AM, Joe Marshall wrote:

> A Scheme procedure might return a value, or it might delegate to another 
> procedure (via tail recursion).  This is a key point: languages without tail 
> recursion cannot delegate to another procedure. They can do a limited 
> simulation of delegation by chaining the returns, but this adds an O(n) space 
> overhead to the computation and consumes stack space, which is a finite 
> resource (hence the limit).
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] idiomatic way to take elements from a thunk?

2012-09-19 Thread Richard Cleis
WARNING: MARGINAL ANSWER AHEAD

I like the following a little more.

(build-list 10 (lambda(v) (thunk)))

rac

On Sep 19, 2012, at 9:57 PM, John Clements wrote:

> WARNING: TOTALLY UNIMPORTANT QUESTION AHEAD.
> 
> I want to enumerate the first 10 values returned by a thunk. I came up with 
> 
> (define thunk (lambda () 14))
> 
> (for/list ([i 10][e (in-producer thunk #f)]) e)
> 
> … but I feel like there must be some way to simply write (stream-take thunk 
> 10). Am I missing something obvious?
> 
> 
> John
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



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


[racket] LAPACK FFI

2012-10-20 Thread Richard Cleis
Is anybody working on the LAPACK FFI listed on the Hackathon page?
How does "BSD Licensed Matrix Library" apply to a Racket FFI?
I'd like to know which makes more sense:

- write/find the few Gaussian Elimination solvers that I need

- Figure out how to do it with FFI and LAPACK

rac


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


Re: [racket] LC53

2012-11-17 Thread Richard Cleis
Only excessively brave Racketeers would attempt that without a good set of 
examples. :-)

rac

On Nov 17, 2012, at 4:46 AM, Hugh Aguilar wrote:

> All of this talk about using Racket for numerical work reminds me of a simple 
> function that I included in my novice package:
> http://www.forth.org/novice.html
> This is the LC53 linear-congruential prng (pseudo-random number generator) 
> that I invented. Here it is using infix pseudo-code:
> m = 2^32 - 5
> a = 2^32 - 3
> x(n+1) = a*x(n) mod m
> 
> Would any brave Racketeer care to implement this in Racket? Hopefully doing 
> so won't involve rewriting the VM and the JIT. :-)
> 
> Note that when I invented LC53, the 32-bit x86 was still prevalent and I was 
> assuming that the system would be 32-bit. Implementing LC53 on the 64-bit x86 
> using 64-bit registers is too easy --- so for this exercise, please assume 
> that you are using a 32-bit processor. As often happens in numerical 
> programs, overflow of intermediate values will be an issue.
> 
> BTW --- My novice package also includes a program to crack an encryption 
> system based on LC53 or any other linear-congruential prng.
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] LC53

2012-11-17 Thread Richard Cleis
I am not familiar with your subject matter, or your point. Without a set of 
inputs and outputs, I cannot discern if I succeeded.

#lang racket

(define (make-f n-bits k1 k2)
  (define limit (expt 2 n-bits))
  (define m (- limit k1))
  (define a (- limit k2))
  (lambda (i x) (modulo (* a x) m)))

(define (g n f lox)
  (cond ((<= n 0) lox)
(else (g (sub1 n) f (cons (f n (car lox)) lox)

(g 4 (make-f 32 5 3) '(123456789)


'(386481 806650895 1510242424 1116891036 123456789)

rac


On Nov 17, 2012, at 5:24 AM, Hugh Aguilar wrote:

> Well, if by "examples" you mean valid values for X, any 32-bit number other 
> than 0 will work.
> 
> From: Richard Cleis 
> To: Hugh Aguilar  
> Cc: "users@racket-lang.org"  
> Sent: Saturday, November 17, 2012 4:59 AM
> Subject: Re: [racket] LC53
> 
> Only excessively brave Racketeers would attempt that without a good set of 
> examples. :-)
> 
> rac
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Bug in bitwise-bit-field

2014-06-16 Thread Richard Cleis
What do you get when you evaluate #b11100010 ?

rac

On Jun 16, 2014, at 9:32 PM, Roman Klochkov wrote:

> ;; from Racket reference 4.2.2.6
> (define (bitwise-bit-field* n start end)
>(bitwise-and (sub1 (arithmetic-shift 1 (- end start)))
>(arithmetic-shift n (- start
> 
> > (bitwise-bit-field #b11100010 0 31)
> -30
> > (bitwise-bit-field* #b11100010 0 31)
> 2147483618
> 
> Racket 6.0.1, Windows XP x86
> 
> -- 
> Roman Klochkov
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


Re: [racket] Performance. Higher-order function

2014-08-03 Thread Richard Cleis
If I (define i->c integer->char), and use it in your test1, it becomes the 
slowest.
That might mean that the "unknown function" response from Dr F applies to your 
function, too.
In other words, I think this is another example of drawing ambiguous 
conclusions from tests that are too simple.
I gave up on benchmarks long ago, because there are too many people outsmarting 
too many other people. 

Interesting, though (uh oh, I am getting sucked in): 
In v5.3.1 all of your tests are the same speed.
I even added some tests that use 'currying' to perhaps prevent the conversion 
function from being "inspected" on every call, and those are the same speed, 
too.

So it seems that the outsmarting peeps who wrote v6.1 optimized your first 
test, somehow, to make it twice as fast when it uses a "known function".

I am somehow reminded of the Fortran days and "intrinsic functions", but don't 
know if that is the same issue as this one.

rac


On Aug 3, 2014, at 3:15 AM, Roman Klochkov wrote:

> Are higher order function always slow?
> 
> Made small test:
> test1 -- unfamous set-in-the-loop accumulating
> test2 -- built-in build-string
> test3 -- manually written build-string with the same code as in test1
> 
> (define (test1 n)
> (define res (make-string n))
> (for ([i (in-range n)])
> (string-set! res i (integer->char i)))
> res)
> 
> (define (test2 n)
> (build-string n integer->char))
> 
> (define (build-string1 n proc)
> (define res (make-string n))
> (for ([i (in-range n)])
> (string-set! res i (proc i)))
> res)
> 
> (define (test3 n)
> (build-string1 n integer->char))
> 
> (time (for ([i 10]) (test1 100)))
> (time (for ([i 10]) (test1 100)))
> (time (for ([i 10]) (test1 100)))
> (displayln "")
> (time (for ([i 10]) (test2 100)))
> (time (for ([i 10]) (test2 100)))
> (time (for ([i 10]) (test2 100)))
> (displayln "")
> (time (for ([i 10]) (test3 100)))
> (time (for ([i 10]) (test3 100)))
> (time (for ([i 10]) (test3 100)))
> 
> Tested on Linux x32
> 
> $ /usr/racket/bin/racket 
> Welcome to Racket v6.1.
> > (enter! "test") 
> cpu time: 360 real time: 469 gc time: 64
> cpu time: 212 real time: 209 gc time: 0
> cpu time: 208 real time: 208 gc time: 0
> 
> cpu time: 400 real time: 402 gc time: 0
> cpu time: 380 real time: 382 gc time: 4
> cpu time: 384 real time: 383 gc time: 0
> 
> cpu time: 524 real time: 529 gc time: 4
> cpu time: 468 real time: 470 gc time: 8
> cpu time: 412 real time: 414 gc time: 12
> 
> ---
> 
> So I see, that build-string version is about two times slower, than 
> set-in-the-loop. Why so much? I expected about 10-20% difference.
> 
> -- 
> Roman Klochkov
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users


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


[racket] Oh, load! Where art thou?

2010-07-23 Thread Richard Cleis
Given a file of "some-scheme.rxt":

*
;#lang racket

(define a-var 'a-val)
*

and a program in a definitions window:

*
#lang racket

(define (f) (load "some-scheme.rkt"))
;(f)
*

... Entering (f) in the interactions window defines a-var.

If the comment is removed from ;#lang racket, a-var is not defined.  Where did 
it go?

If the comment is removed from ;(f), an 'unbound identifier' error is triggered 
during the Run. [(f) still works in the interactions window.] Which identifier 
is unbound?  

How can I explain where (load) evaluates it's contents?

Does (load) have a future in racket?

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


Re: [racket] syntax, differently

2010-07-31 Thread Richard Cleis



RAC

On Jul 31, 2010, at 9:51 AM, Eli Barzilay  wrote:


On Jul 31, Robby Findler wrote:

On Sat, Jul 31, 2010 at 10:00 AM, Matthias Felleisen
 wrote:


Shriram's proposal and a private conversation with Mike suggested
the following feature requests for the drracket teaching
languages:

1. Could drracket limit the width of programs in the teaching
  language world to 80 columns?


This one seems doable (I'd probably make the text turn red when it
passes the 80th column or somethign instead of rejecting
keystrokes).


Ha!  Back in Cornell I had a "DrSwindle" thing, which was a hack of
DrScheme that was needed since it was in the pre-module-days and
swindle was changing too much fro DrScheme to work.  One feature that
I was sneaking in in addition to making it work with Swindle was an
80-character line limit, which I've always wanted.

So, it would be nice if there was a general option to turn this on,
not only for the student languages.



2. Could drracket reindent all every time a programmer hits
  {return | run | submission server request }?


I reindent-all/check-syntax subconsciously, so my hot keys for  
reindent would last longer.  I'd like reindenting and reformatting to  
occur whenever 80 lines is approached, within the current definition  
under edit.  In effect, do automatically what Dr already does nicely:  
highlight from "(define..."  to the insertation point, and hit tab. I  
program by shooting for 72, and accepting 80 if necessary.


RAC




I'd be worried about this that some edits one does (maybe opening a
string?) would cause strange things to happen to the editor based on
intermediate states of the program. [...]


(And from a non-teaching-language perspective, there are cases where
you want to change the indentation for some reason.  (*I* do that
too.))

--
 ((lambda (x) (x x)) (lambda (x) (x x)))  Eli  
Barzilay:
   http://barzilay.org/   Maze is  
Life!

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

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


Re: [racket] syntax, differently

2010-07-31 Thread Richard Cleis

I think we are talking about several things, here.

One of them is about reformatting the whole file and another is  
reformatting locally when the programmer is approaching a line length  
of 80.


I program with full trust in the Dr's ability to auto-indent and check- 
syntax, so I do both constantly.  That way, I am never surprised by a  
big change in the file.  Nearly the same result could almost be  
achieved by live auto formatting of only the definition undergoing  
editting.  ('almost', because there are ghosts to haunt anyone who  
attempts such an implementation).  I would have attempted this awhile  
ago if I knew how to get started.


The line-length issue is one that could partly be handled by allowing  
the programmer to size the editting window  to exactly the correct  
length, then manually edit to eliminate wrappings. However, I wouldn't  
mind if the Dr took the scapel and tried to fix it for me.


RAC

On Jul 31, 2010, at 1:42 PM, Jos Koot  wrote:


I am not a student, but try to think and do like student now.

I would be very frustrated when all the time I run a program, my  
code would
be reindented and get quite another appearance. WHAT HAPPENS HERE,  
would be
my first thought. Reindenting a file before saving it would give me  
the same
surprise when opening it again. Wow, this apparently is not the  
program I

have entered. Where is my program???

Nevertheless I agree with Matthias that indentation is a very  
helpfull tool.
But doing that without explicit request seems confusing to me (at  
the least)


Just a strong advice to type control-I from time to time would not be
adaquate? Furthermore, typing a program with the standard indentation
settings already gives indentation while typing. Wow, that's not the
indentation I expected after my last line-break. Ho, I see, a  
parenthesis
too much or too less in the previous line. No problem, add or remove  
it

followed by control-I.

BTW, for myself I prefer indentation by exactly as many spaces as  
there are
unsatisfied open parentheses (for as far as possible, for shotcuts  
like '''

and '#'' and '#,@' may inhibit my preferred indentation.)

Jos


-Original Message-
From: users-boun...@racket-lang.org
[mailto:users-boun...@racket-lang.org] On Behalf Of Matthias  
Felleisen

Sent: 31 July 2010 21:14
To: Robby Findler
Cc: Eli Barzilay; racket List
Subject: Re: [racket] syntax, differently


The file wouldn't move all the time. It would move on RUN and
on SAVE.

Most experienced programmers wouldn't see any movement whatsoever.
Students would see movement for a short time. Then they'd
follow the flow.

-- Matthias





On Jul 31, 2010, at 2:25 PM, Robby Findler wrote:


Thinking as someone who would be implementing these changes, I can
easily see a whole slew of bug reports coming in of the

form "When I

save my file DrRacket moves all the lines around. What's

going on?!".

So, while I agree that there is something to be done here vis a vis
indentation help in the PDE, I don't think we quite are at

the "try to

implement it and play with it" stage yet.

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


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



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

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


Re: [racket] syntax, differently

2010-08-01 Thread Richard Cleis
[snip]
> I was trying to emphasize that it may be harder to students to keep their 
> code neater compared to some other languages which usually have code that 
> rarely exceed 1 line.
> 
> Example:
> Racket using the universe teachpack:
> 
> (define (s-mouse-engine s x y event)
>   (cond
> [(and 
>   (and (> x 248)   (< x 424)) 
>   (and (> y 570)   (< y 649)))
> (make-S-STATE
>  (get-s-background s);;I have made methods here to 
> reduce length, but other wise it would be longer.
>  (make-button
>   (s-mouse-engine-worker1 event "button-img")
>   (get-s-button-x s)   ;;I have made methods here to 
> reduce length, but other wise it would be longer.
>   (get-s-button-y s)   ;;I have made methods here to 
> reduce length, but other wise it would be longer.
>   (s-mouse-engine-worker1 event "button-initiate")))]

How would you write that in another language that rarely exceeds one line?

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

Re: [racket] syntax, differently

2010-08-01 Thread Richard Cleis
Perhaps this is related to some of what you are saying: For years I  
put double spaces after every initial element that had more purpose  
than a basic function (define, cond, let, etc.) I wish I had time to  
make a formatter do that, because I still like it.


RAC

On Aug 1, 2010, at 7:23 PM, Ray Racine  wrote:

Ah yes, re-playing back those early scheme days in my head.  As all  
do and did,  I wrested with parens, and recursion.  Recursion did  
finally click and even now 1/2 the time I find myself "looping" with  
a recursive function in Scala.  I don't give it second thought, it  
does confuse the hell out of others however who read the code.  Even  
funnier, I now think how come they can't seem to "get it".  But it  
did kick my ass in the day.


But parens   I did finally make a separate peace with parens,  
but in a very unique manner.  It turned out it wasn't the parens  
after all it was the pseudo special forms/keywords + parens that  
created the dissonance.


As a joke, literally two beers bored as hell on Friday night what- 
the-hell-as-a-joke exercise, I used emacs to redefine each of the  
common special-form / keywords to single greek letters. lambda ->  
lambda-char, define -> lower-delta, if -> lower-iota, begin -> lower- 
rho, let -> lower-beta, set! -> lower-sigma, 'and', 'or', 'not' ->  
the single char logic symbols, #t #f -> top and bottom symbols, etc.


I read rho means 'r'un.  I read beta as 'b'ind.  I read sigma as  
's'et! etc.  And a few years later, I'm still coding in joke mode.


Sigma (set!) is a bright red char.  All others in chars in a light  
blue.  I use a black background, and parens are in a light grey, you  
almost can't see them.  I constantly let emacs indent and 'tab'  
lines into place.  In other words, indentation guides first, parens  
second and as the last resort when I get 'lost'.


All other text is bright white on black.  Nesting is more  
symmetrical and cleaner.  I'm sure everyone out there will just hate  
it.


So where am I going with this.   Just tossing out the thought that  
its not the parens per se, but parens combined with the core forms  
which are the issue.  Particularly: define, let, begin, if.


Very curious if its just an odd twist to my mental makeup, I'm  
slightly dyslexic as well, or some others might end up seeing it the  
same way.


Skeptical??  I believe DrRacket added delta (for 'define') and  
lambda greek char capability long ago.  May have even been driven  
from an earlier posting by me on this very topic to the list a  
number of years back.  Complete the experiment by adding single  
greek chars aliases for 'let', 'begin',  et al.


You're probably wondering by now, so without further ado, Ladies and  
Gentleman I give you "Funky Racket Syntax" http://imagebin.ca/view/s6SHn7c.html


I tried to actually pick "bad" examples.  I'm sure you'll all agree  
I succeeded.




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

Re: [racket] Nested scope in D vs Racket

2010-08-21 Thread Richard Cleis


On Aug 21, 2010, at 1:21 PM, Shriram Krishnamurthi   
wrote:



Your reduction of this guideline to what you claim Hansen preached (I
haven't seen that essay) is unfair.  The D guideline does not say
"don't have nested scope".  It says to not allow lexical re-binding,
which is a much, much finer point.
...



I mean, it's all visible in scope, so renaming is easy; why not just
give it a different name?  It might even be clearer to the reader!


It might not. In the it-only example, the reader knows that the outer  
bindings cannot be used by the inner ones, so the reader can read  
inward without having to be warey of the outer bindings.  In the itsy- 
bitsy example, the reader cannot immediately discern whether the outer  
bindings are used by the inner ones.  On rare occasions I have  
intentionally shadowed variables for this reason (e.g., coordinate  
transformations.)


RAC




 (let ([it 5])
   (+ ...
  (let ([it 10])
(... ...
 ...
 it

Uh, which `it'?

 (let ([itsy 5])
   (+ ...
  (let ([bitsy 10])
(... ...
 ...
 bitsy

(Aha, not `itsy'!)

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

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


Re: [racket] Remote execution in Racket

2010-08-24 Thread Richard Cleis
Can you provide an example? (At this point, one of the profs around  
here asserts, "Code, please." :)


RAC

On Aug 24, 2010, at 1:02 AM, Frederick Ross  wrote:

On Sat, Aug 21, 2010 at 8:07 PM, Neil Van Dyke  
 wrote:
For example, is there a reason that you cannot simply generate a  
small
Scheme code file to that temporary directory, expressing whatever  
is needed
for the batch run on the cluster?  If not, is the barrier the  
programming
difficulty in capturing sufficient context to express in that  
generated

Scheme file, or is the barrier one of run-time performance?


The barrier is context.  If at a repl you define a bunch of stuff,
then an arbitrary execution which should capture all that context
code, and run it on another computer entirely, I couldn't think of
another way to do it.

After responses on this list, I'm thinking about just letting users
send scripts for execution (i.e., Racket modules), and not trying to
do this "clean" solution at all.

--
Frederick Ross
Bioinformatics and Biostatistics Core Facility
Life Sciences, EPFL
http://bbcf.epfl.ch/
+41 21 693 14 39
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users

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


Re: [racket] What is inexactness about?

2010-09-01 Thread Richard Cleis

On Sep 1, 2010, at 7:40 AM, Stephen Bloch wrote:

> On Sep 1, 2010, at 9:29 AM, Matthias Felleisen wrote:
> 
>> The #i indicates inexactness as far as computer arithmetic is concerned, 
>> that is, what the so-called 'machine' level arithmetic supplies.
> 
> And yet Scheme/Racket allows for inexact integers, whereas no computer I know 
> of has an inexact integer type supported at the machine level.

Don't forget some fun stuff (for which there are sound reasons):

> (inexact? (sin 0))
#f
> (inexact? (sin 0.0))
#t
> 

rac

> 
> 
> Stephen Bloch
> sbl...@adelphi.edu
> 
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] keyboard input help?

2010-09-21 Thread Richard Cleis
Have you read about get-key-code (and other related functions) in the docs? On 
earlier versions of PLT Scheme I was investigating things like:

(on-subwindow-char the-win key-event)
(display (send key-event get-key-code))

I don't know how much things have changed since then.

>From the short description of what you are trying to do, I am not convinced 
>that you need to process one input character at a time. Racket readers are 
>hard to beat.

rac

On Sep 20, 2010, at 11:16 PM, Isaiah Gilliland wrote:

> I was wanting to see if there was at all a way to do asynchronous input from 
> a keyboard in racket. Kinda like tcp-listen, that won't freeze up the program 
> while it's used, and won't show in the terminal. I've just finished my first 
> small utility in Scheme and want to move to something a bit more complicated. 
> I'm going to try to create a cli text editor with a focus on lisp 
> programming, but possibly able to extend to other languages. 
> The reason I want input straight from the keyboard is because I want to 
> process the input for paren matching and do some formating before I print it. 
> I guess I'm wondering if there is a way I can listen to keyboard events 
> directly.
> Any info whatsoever would help me a lot, thanks 
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Scripting on the Mac

2010-09-22 Thread Richard Cleis
Several years ago (in other words, I don't remember exactly what I was doing), 
I used PLT's 'process' and 'system' commands to access the Open Scripting 
Architecture essentially from the command line. It was slightly tricky to get 
the responses back into Scheme, but I do remember that the amount of code 
development was almost nothing. It was fun, too. DrScheme's timing was good 
enough that I had the voice software 'singing' stuff like Row Row Row your boat 
'in a round', simply by using classic Scheme primitives and threaded process 
(or system) calls.

I never pursued an OSAX solution due to the success of the above (I was doing 
it for more important reasons than the fun), and now I don't do stuff like that 
at all.

rac


On Sep 21, 2010, at 4:49 PM, Michael Smith wrote:

> Hi,
> 
> I am a Mac user and have just started to learn Scheme. Many apps on the Mac 
> are scriptable via Applescript. Is there any Scheme way to leverage this 
> capability, like an Applescript bridge?
> 
> Thanks,
> 
> Mike
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


[racket] Local Development

2010-09-25 Thread Richard Cleis
Where should modules and docs, developed for local use, be located?  The docs

file:///Applications/Racket%20v5.0.1/doc/unstable/guidelines.html?q=guidlines

indicate that the 'unstable' directories are the place to put new modules, but 
that may be for modules which are eventually intended to be delivered with 
Racket.

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


Re: [racket] Local Development

2010-09-25 Thread Richard Cleis

On Sep 25, 2010, at 12:20 PM, Neil Van Dyke wrote:

> Richard Cleis wrote at 09/25/2010 01:48 PM:
>> Where should modules and docs, developed for local use, be located? 
> I do it one of two ways, depending on the project:
> 
> * An arbitrary directory, with a subdirectory for each of what I loosely 
> consider a 'package', and each such subdirectory having a PLaneT *development 
> link* to it.  Actually, I like to have these correspond to potential future 
> PLaneT packages or future versions of existing PLaneT packages.

Where do the docs end up when using raco setup -l ?  I didn't try making a 
development link to my arbitrary directory, and had no luck using setup to make 
docs outside of collects. Is the development link sufficient to build them 
inside .../arb-dir/docs?

rac


> 
> (Note: if you do it this way for internal code, by default there is a 
> security weakness, in that there are multiple situations in which a "require" 
> intended for your internal code winds up going to the PLaneT repository, 
> which can result in untrusted code being evaluated.  I think that a good 
> solution for this relatively low risk will fall out of some other deployment 
> and security enhancements for PLaneT that people have started talking about.)
> 
> * An arbitrary directory, with a subdirectory for each Racket *collection*, 
> and then setting the "PLTCOLLECTS" environment variable to include that 
> directory.  This is the pre-PLaneT way to do it, and it still has its uses.
> 
> The main drawback to this is that you need "PLTCOLLECTS" to be set 
> appropriately for all your tools, which can be a headache if you need to 
> change "PLTCOLLECTS" depending on what project or version control workspace 
> you're working on that hour.  Although, if your projects don't all use the 
> same version of Racket, you might as well have your "Makefile" set 
> "PLTCOLLECTS" when it runs the tools with the full paths to the appropriate 
> versions of the tools for that project.
> 
> -- 
> http://www.neilvandyke.org/

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


[racket] Scribbling Docs

2010-09-30 Thread Richard Cleis
Scribbling Documentation 4.1.4, Defining Racket Bindings, shows how to  
access a module function and 4.1.5  documents evaluating examples.


I cannot get a function to be recognized.  It 'turns' bright blue, but  
has a red underline.  What do I misunderstand?


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


[racket] test

2010-10-03 Thread Richard Cleis
rac
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


[racket] Example in Docs

2010-10-05 Thread Richard Cleis
I am trying the examples in 4.1.  When rendered via the Scribble HTML button, 
the function my-helper is underlined in red.  What does that mean?

The mouse-over works, and check-syntax in the scrbl file draws the arrows that 
indicate that the function is in helper.rkt. When I use raco setup, the 
documentation appears to be correct (but my-helper has a red line).

rac


manual.scrbl:

#lang scribble/manual
@(require (for-label racket
"helper.rkt"))

@title{My Library}

@defmodule[my-lib/helper]

@defproc[(my-helper [lst list?])
(listof
 (not/c (one-of/c 'cow)))]


helper.rkt:

#lang racket

(provide/contract
[my-helper (-> list? (listof (not/c (one-of/c 'cow])

(define (my-helper lst) '(whatever))


info.rkt:

#lang setup/infotab
(define scribblings '(("manual.scrbl" (
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] extract polygon information from an image is it silly thinking?

2010-10-10 Thread Richard Cleis

On Oct 10, 2010, at 7:28 AM, 김태윤 wrote:

> extract polygon information from an image is it silly thinking?

No.

> hello
> I was told that when it comes to compare with polygon and image rotating, 
> polygon is much faster.
> and an obviously simple idea come across my mind.
> then why don't I change image into much simpler colored polygon?

It can take a lot of polygons.

> feel like it is ok because I don't care about loosing detail of image.
> it's ok if I can just figure out how it looks like.
> making polygon scheme code from an image, is it silly thinking?
> and is it possible makeing 3d character from three-demensional image?
> if it is not a silly thinking, 
> what would it be good for first step?

A good first step depends on how much time you want to spend, how much math you 
like to do, etc.  I used a text book that someone loaned to me, written by:

http://www.cs.unm.edu/~angel/CS433/LECTURES/CS433_00.pdf

That may be more than you want.


> I think I need to know how to get information from image first.
> do you have any advice?

That is a big subject.  You might want to have some fun first.  For example, 
take the corners of an image and make one rectangle from the color information 
in the corners. Then do the same thing with four rectangles inside of the 
first. Keep doing it with more and more rectangles and see what happens as you 
invent better algorithms for making the rectangles. Racket is a fun language to 
use for such investigation.

rac


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

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

Re: [racket] [BULK] Fundamentals

2010-10-14 Thread Richard Cleis
As someone who doesn't know better, I like your post.  Can you explain 'script' 
?

rac

> The definitions are clear and have not changed.  If you have a machine
> that runs programs written in language M, but you have a program
> written in language L, you can proceed in one of two ways:
> 
>  1)  You can modify the *machine* to run programs in a different language.
>An interpreter is a program that transforms a machine into
> another machine.
> 
>  2)  You can find an `equivalant' program in the language the machine does 
> run.
>A compiler is a program that transforms a program into another program.
> 
> Interpretation or compilation is a relationship between machines and programs.
> It isn't a property of the language.  Shriram Krishnamurthi had the most 
> correct
> response:
>The phrase "interpreted language" has no meaning; it's nonsensical.
> 
> -- 
> ~jrm
> 
> ** I suppose we could argue a little bit.  If the notion of
> `equivalent program' were
> poorly defined, then you might find it very hard to write a compiler.
> (Or, having
> written one, determining if it works correctly.)  It is possible to
> create a programming
> language that is so hard to statically analyze that the best you can do is
> to `inline the interpreter'.  You might call such a language an
> `interpreted language'.
> Scheme and Racket, however, do not fall into this category.
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


Re: [racket] [BULK] Fundamentals

2010-10-14 Thread Richard Cleis
How would he respond to questions that I must answer: "You use Racket? For 
scripting or for programming? Is Racket interpreted or compiled?"

rac

On Oct 14, 2010, at 12:51 PM, namekuseijin wrote:

> On Thu, Oct 14, 2010 at 3:14 PM, Richard Cleis  wrote:
>> As someone who doesn't know better, I like your post.  Can you explain 
>> 'script' ?
> 
> as Larry Wall put it:
> "Suppose you went back to Ada Lovelace and asked her the difference
> between a script and a program. She'd probably look at you funny, then
> say something like: Well, a script is what you give the actors, but a
> program is what you give the audience. That Ada was one sharp lady..."
> 
> source:
> http://en.wikiquote.org/wiki/Larry_Wall#The_State_of_the_Onion_11

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


Re: [racket] [BULK] Fundamentals

2010-10-14 Thread Richard Cleis
Ok. But...  Carrions de Dwimmerlaik provide funding; they want answers  
to these questions.


RAC

On Oct 14, 2010, at 2:16 PM, Robby Findler  
 wrote:



'Begone foul dwimmerlaik, lord of carrion! Leave the dead in peace!'

On Thu, Oct 14, 2010 at 2:56 PM, namekuseijin  
 wrote:

he would probably look at you funny and point you to Amazon.com and
some deep obscure Lord of the Rings passage.

On Thu, Oct 14, 2010 at 4:36 PM, Richard Cleis   
wrote:
How would he respond to questions that I must answer: "You use  
Racket? For scripting or for programming? Is Racket interpreted or  
compiled?"


rac

On Oct 14, 2010, at 12:51 PM, namekuseijin wrote:

On Thu, Oct 14, 2010 at 3:14 PM, Richard Cleis   
wrote:
As someone who doesn't know better, I like your post.  Can you  
explain 'script' ?


as Larry Wall put it:
"Suppose you went back to Ada Lovelace and asked her the difference
between a script and a program. She'd probably look at you funny,  
then
say something like: Well, a script is what you give the actors,  
but a
program is what you give the audience. That Ada was one sharp  
lady..."


source:
http://en.wikiquote.org/wiki/Larry_Wall#The_State_of_the_Onion_11




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


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


Re: [racket] [BULK] Fundamentals

2010-10-14 Thread Richard Cleis
I can picture John Cleese, wearing a legal wig, delivering your advise  
in episode n.


RAC

On Oct 14, 2010, at 2:33 PM, Robby Findler  
 wrote:



Ah. Then the answers are "scripting" and "compiled". Unless they want
to hear "programming" and "compiled". Basically any of the four
possible answers are all correct (insomuch as the questions actually
make sense).

Robby

On Thu, Oct 14, 2010 at 3:23 PM, Richard Cleis  wrote:
Ok. But...  Carrions de Dwimmerlaik provide funding; they want  
answers to

these questions.

RAC

On Oct 14, 2010, at 2:16 PM, Robby Findler >

wrote:


'Begone foul dwimmerlaik, lord of carrion! Leave the dead in peace!'

On Thu, Oct 14, 2010 at 2:56 PM, namekuseijin >

wrote:


he would probably look at you funny and point you to Amazon.com and
some deep obscure Lord of the Rings passage.

On Thu, Oct 14, 2010 at 4:36 PM, Richard Cleis   
wrote:


How would he respond to questions that I must answer: "You use  
Racket?
For scripting or for programming? Is Racket interpreted or  
compiled?"


rac

On Oct 14, 2010, at 12:51 PM, namekuseijin wrote:

On Thu, Oct 14, 2010 at 3:14 PM, Richard Cleis   
wrote:


As someone who doesn't know better, I like your post.  Can you  
explain

'script' ?


as Larry Wall put it:
"Suppose you went back to Ada Lovelace and asked her the  
difference
between a script and a program. She'd probably look at you  
funny, then
say something like: Well, a script is what you give the actors,  
but a
program is what you give the audience. That Ada was one sharp  
lady..."


source:
http://en.wikiquote.org/wiki/Larry_Wall#The_State_of_the_Onion_11




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




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


Re: [racket] [BULK] Fundamentals

2010-10-15 Thread Richard Cleis
I like these arguments, but those who ask the unanswerable questions about 
compiling, interpreting, and scripting wouldn't get the details.  From your 
answer and JRMs, I might try to stick to: "Racket is JIT-compiled too", and it 
even runs lightweight languages like R5RS Scheme. The point is to relieve fear 
and maintain access to charge numbers provided by those who are justifiably 
skeptical of any claim of improved ways of developing software.

rac


On Oct 14, 2010, at 3:04 PM, namekuseijin wrote:

> the ultimate answer is 42.  Now you just need the proper question...
> 
> here's another take:  java is JIT-compiled too.  It powers a very
> large industry.  The difference to Racket is just a few million
> dollars worth of hype, man-power and a (largely) static verbose
> type-system:  this provides a tad better oportunities for the compiler
> to pin down optimizations.
> 
> so, you wonder if you should take Racket as a lowly interpreted
> scripting language or as a noble compiled programming language?
> 
> I have no way to answer you, but here are a few facts for you to
> ponder and make your decision:
> 
> Amazon.com was originally written in Perl (later at least mostly
> rewritten as C++)
> Twitter.com was originally written in Ruby (later rewritten as Scala
> running on JVM)
> Reddit.com was originally written in Common Lisp (later rewritten in Python)
> Slashdor.org was originally written in Perl.
> Facebook.com is written in PHP.
> 
> these are some heavy-traffic websites.  If a bytecode-interpreted
> "scripting" language can do some "real programming", then certainly a
> JIT-compiled language can more than handle a  smaller website or a
> single-user desktop app.

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


Re: [racket] Racket and music

2010-10-16 Thread Richard Cleis
Analyze sounds from a microphone?

rac

On Oct 16, 2010, at 4:56 PM, Sébastien Cano wrote:

> Hi everyone,
> 
> I'm a beginner in Racket and I plan to make a rhythm game.
> Do you think it is possible? Would it be easy?
> I don't know where to start from.
> The program has to analyze sounds, and that's the hard part...
> 
> Thanks in advance.
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Racket and music

2010-10-16 Thread Richard Cleis
I have never read or played sound files with Racket, except via system calls. 
Some Racketeers have implemented PortAudio. You can check the PLaneT server for 
that. Precise synchronization of I/O and sound is tricky.  With what kind of 
programming are you familiar?

rac



On Oct 16, 2010, at 8:25 PM, Sébastien Cano wrote:

> yes
> 
> 2010/10/17 Richard Cleis 
> I am guessing that you want to have some sort of input for rhythm, and 
> analyze the music to see if the player is 'on the beat'. Is that right?
> 
> rac
> 
> On Oct 16, 2010, at 7:54 PM, Sébastien Cano wrote:
> 
>> From a wav or mp3.
>> 
>> 2010/10/17 Richard Cleis 
>> Analyze sounds from a microphone?
>> 
>> rac
>> 
>> On Oct 16, 2010, at 4:56 PM, Sébastien Cano wrote:
>> 
>> > Hi everyone,
>> >
>> > I'm a beginner in Racket and I plan to make a rhythm game.
>> > Do you think it is possible? Would it be easy?
>> > I don't know where to start from.
>> > The program has to analyze sounds, and that's the hard part...
>> >
>> > Thanks in advance.
>> > _
>> >  For list-related administrative tasks:
>> >  http://lists.racket-lang.org/listinfo/users
>> 
>> 
> 
> 

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

Re: [racket] Are there any functional structs in Racket

2010-10-21 Thread Richard Cleis

On Oct 20, 2010, at 11:16 PM, Nikita B. Zuev wrote:

> Thank you all for your replies. I somehow missed `struct-copy', this
> is exactly what I wanted. Bad thing I can't pass lambda to it like:
> 
> (struct-copy person
> myperson
> (age (lambda (age) (+ age 1
> 

struct-copy expects an expression, so the lambda isn't necessary. It doesn't 
require id's in the expression to be from the same structure (or to be part of 
a structure at all). If you are writing a lot of code that requires a special 
form like the above, then you can write a function or macro to do it. The 
following expression is just as short and easy (easier?) to read, anyway.

(struct-copy person myperson (age (+ 1 (person-age myperson

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

Re: [racket] there must be function right after parenthesis?

2010-10-26 Thread Richard Cleis

On Oct 26, 2010, at 1:11 AM, kty1...@gmail.com wrote:

> there must be function right after parenthesis?
> hello~
> while I am learning GUI programming in DrRacket,
> I don't get how string literal can be placed right after parenthesis
> such as 
> (define frame (instantiate frame% ("Example")))

("Example") is attempting to evaluate the function "Example" with no arguments. 
You probably don't want the parens.

> (define msg (instantiate message% ("No events so far..." frame)))
> (instantiate button% ("Pause" frame (lambda (button event) (sleep 5
> (instantiate button% ("Ok" panel void))
> I was thought one of the scheme grammar is there must be a function right 
> after parenthesis
> and I don't understand how such a code like
> ((func arg) arg2) works too.

That one will work if the result of (func arg) is a function.  Then that result 
function will be evaluated using arg2. Try this:

(define (func arg-to-multiply)
 (define (func-to-be-used-as-result arg) 
   (* arg-to-multiply arg))
 func-to-be-used-as-result ; result
 )

((func 3) 2)
((func 4) 2)

There are much more useful reasons to use this capability.

rac


> 
> could somebody please let me know how it works?
> thanks in advanced_
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] there must be function right after parenthesis?

2010-10-26 Thread Richard Cleis
Oops. Sorry about the first question.  I thought you meant that it did *not* 
work, and I didn't read enough of the code.  As CV showed, 'instantiate' is 
defined with special syntax. The language allows for developers to define 
special syntax, too. New forms are normally closely related to the language, 
unless you go to a lot of trouble.

rac


On Oct 26, 2010, at 1:45 AM, Richard Cleis wrote:

> 
> On Oct 26, 2010, at 1:11 AM, kty1...@gmail.com wrote:
> 
>> there must be function right after parenthesis?
>> hello~
>> while I am learning GUI programming in DrRacket,
>> I don't get how string literal can be placed right after parenthesis
>> such as 
>> (define frame (instantiate frame% ("Example")))
> 
> ("Example") is attempting to evaluate the function "Example" with no 
> arguments. You probably don't want the parens.
> 
>> (define msg (instantiate message% ("No events so far..." frame)))
>> (instantiate button% ("Pause" frame (lambda (button event) (sleep 5
>> (instantiate button% ("Ok" panel void))
>> I was thought one of the scheme grammar is there must be a function right 
>> after parenthesis
>> and I don't understand how such a code like
>> ((func arg) arg2) works too.
> 
> That one will work if the result of (func arg) is a function.  Then that 
> result function will be evaluated using arg2. Try this:
> 
> (define (func arg-to-multiply)
> (define (func-to-be-used-as-result arg) 
>   (* arg-to-multiply arg))
> func-to-be-used-as-result ; result
> )
> 
> ((func 3) 2)
> ((func 4) 2)
> 
> There are much more useful reasons to use this capability.
> 
> rac
> 
> 
>> 
>> could somebody please let me know how it works?
>> thanks in advanced_
>> For list-related administrative tasks:
>> http://lists.racket-lang.org/listinfo/users
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


Re: [racket] draw circle over bitmap and erase old circle

2010-10-27 Thread Richard Cleis
Insert the two lines below to see that what you want is possible, but I doubt 
such a quick hack is the right way to do it. 

rac

On Oct 27, 2010, at 8:48 PM, kty1...@gmail.com wrote:

> hello
> I finally circle the bitmap where I point by mouse
> but there are several problem
> 1. the circle filled with white color that I can't see bitmap through the 
> circle
> 2. the drawn circle didn't erased after I point another coordinates
> 
> could somebody give me an little advice?
> 
> my code looks messy and not neat but 
> I paste the code for make it easier to understand
> 
> 
> #lang scheme
> (require 2htdp/image
> racket/gui)
> (define chipset (make-object bitmap% "town.png" 'png))
> (define (check dc m)


 (send dc draw-bitmap chipset 0 0)
 (send dc set-brush "blue" 'transparent)



> (define x (send m get-x))
> (define y (send m get-y))
> (send dc draw-ellipse (- x (modulo x 16)) (- y (modulo y 16)) 16 16))
> (define f (new frame% (label "map editor")))
> (define xymsg (new message% (label "nth so far") (parent f)))
> (define select% 
> (class canvas% 
> (override on-event on-paint)
> (define on-paint (λ () (send (send this get-dc) draw-bitmap chipset 0 0)))
> (define on-event (λ (m) 
> (send xymsg set-label 
> (string-append "x:"
> (number->string (send m get-x))
> " y:"
> (number->string (send m get-y
> (when (send m get-left-down) (check (send this get-dc) m
> 
> (super-new )
> ))
> (new select% (parent f) (min-width (image-width chipset)) (min-height 
> (image-height chipset)) )
> (send f show #t)_
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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

Re: [racket] draw circle over bitmap and erase old circle

2010-10-27 Thread Richard Cleis
Incremental changes like this can work, but a good program design is necessary 
to prevent running into situations that cannot be solved with a few hacks. I 
cannot suggest a better way without knowing your goals.

By the way, in the email I intended to paste those two lines after the 
definitions in that function.  I doubt they should be in that function anyway; 
I threw them in there because I (like you) wanted an easy way to see if what 
you were trying to do was possible.

rac

On Oct 28, 2010, at 12:02 AM, kty1...@gmail.com wrote:

> omg it works!!
> thank you!
> although I am satisfied with this method, 
> do you know the better way for it?
> 
> , Richard Cleis 님이 작성:
> > Insert the two lines below to see that what you want is possible, but I 
> > doubt such a quick hack is the right way to do it.
> > 
> > 
> > 
> > rac
> > 
> > 
> > 
> > On Oct 27, 2010, at 8:48 PM, kty1...@gmail.com wrote:
> > 
> > 
> > 
> > > hello
> > 
> > > I finally circle the bitmap where I point by mouse
> > 
> > > but there are several problem
> > 
> > > 1. the circle filled with white color that I can't see bitmap through the 
> > > circle
> > 
> > > 2. the drawn circle didn't erased after I point another coordinates
> > 
> > >
> > 
> > > could somebody give me an little advice?
> > 
> > >
> > 
> > > my code looks messy and not neat but
> > 
> > > I paste the code for make it easier to understand
> > 
> > >
> > 
> > >
> > 
> > > #lang scheme
> > 
> > > (require 2htdp/image
> > 
> > > racket/gui)
> > 
> > > (define chipset (make-object bitmap% "town.png" 'png))
> > 
> > > (define (check dc m)
> > 
> > 
> > 
> > 
> > 
> >  (send dc draw-bitmap chipset 0 0)
> > 
> >  (send dc set-brush "blue" 'transparent)
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > (define x (send m get-x))
> > 
> > > (define y (send m get-y))
> > 
> > > (send dc draw-ellipse (- x (modulo x 16)) (- y (modulo y 16)) 16 16))
> > 
> > > (define f (new frame% (label "map editor")))
> > 
> > > (define xymsg (new message% (label "nth so far") (parent f)))
> > 
> > > (define select%
> > 
> > > (class canvas%
> > 
> > > (override on-event on-paint)
> > 
> > > (define on-paint (λ () (send (send this get-dc) draw-bitmap chipset 0 0)))
> > 
> > > (define on-event (λ (m)
> > 
> > > (send xymsg set-label
> > 
> > > (string-append "x:"
> > 
> > > (number->string (send m get-x))
> > 
> > > " y:"
> > 
> > > (number->string (send m get-y
> > 
> > > (when (send m get-left-down) (check (send this get-dc) m
> > 
> > >
> > 
> > > (super-new )
> > 
> > > ))
> > 
> > > (new select% (parent f) (min-width (image-width chipset)) (min-height 
> > > (image-height chipset)) )
> > 
> > > (send f show #t)_
> > 
> > > For list-related administrative tasks:
> > 
> > > http://lists.racket-lang.org/listinfo/users
> > 
> > 
> > 
> >

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

Re: [racket] Making namespaces meet

2010-11-05 Thread Richard Cleis
Have you read Guide:Racket 15.1 ?  A practical example might help. I think your 
second example is the same as the first, since eval uses the current namespace 
if none is provided.

rac

On Nov 5, 2010, at 5:53 AM, Jukka Tuominen wrote:

> 
> Hi,
> 
> I'm having trouble of getting namespaces meet when making dynamic
> definitions. I made a simple example below.
> 
> ((lambda ()
>  (define x 10)
>  (eval (list 'define 'y 5))
>  (+ x y)))
> 
> ;>> reference to undefined identifier: y
> 
> 
> 
> I then tried to "store" one of the namespaces and pass it on to another, but
> I guess that's not the way the namespaces work.
> 
> 
> 
> ((lambda ()
>  (define namespace (current-namespace))
>  (define x 10)
>  (eval (list 'define 'y 5) namespace)
>  (+ x y)))
> 
> ;>> reference to undefined identifier: y
> 
> 
> Any ideas how to solve this?
> 
> br, jukka
> 
> 
> |  J U K K A   T U O M I N E N
> |  m a n a g i n g   d i r e c t o r  M. A.
> |
> |  Finndesign  Kauppiaankatu 13, FI-00160 Helsinki, Finland
> |  mobile +358 50 5666290
> |  jukka.tuomi...@finndesign.fi  www.finndesign.fi
> 
> 
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] letoverlambda

2010-11-20 Thread Richard Cleis

On Nov 20, 2010, at 12:25 PM, Jos Koot wrote:

> Having read some of the stuff, l am not impressed. Yes, in some cases we may
> want to introduce a binding not named in a macro call. Racket and R6RS
> (macro-case) do that very well. That for a beginner it is difficult to
> prepare unhegienic macros: jolly good! I have misused datum->syntax a couple
> of times, just to find out later that I did not need it realy (although I
> recognize that in some cases it may be usefull)
> Jos

My experiences are similar. On the few occasions that I have used unhymacs, I 
first wrote and debugged hymacs; this path allows macro novices like myself to 
see and justify (or not) the need for developing them into unhymacs. To me, 
good development environments provide 'complication stages' that can be clearly 
understood and encountered only when required.

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


Re: [racket] Plea for neologism (was: Re: letoverlambda)

2010-11-24 Thread Richard Cleis
These two threads remind me of an observation that I wish I could cite:

"Debugging programs is harder than writing programs. Those who write programs 
at the limits of their ability are unqualified to debug them."

In this case: "Macros are harder to understand than fundamental programming. 
Those who use macros at the limits of their ability are unqualified to talk 
about them."

So, why are new words needed? 

rac



In this case
On Nov 23, 2010, at 12:08 PM, John Clements wrote:

> 
> On Nov 20, 2010, at 6:58 PM, Matthias Felleisen wrote:
> 
>> 
>> On Nov 20, 2010, at 9:01 PM, Greg Hendershott wrote:
>> 
>>> But I didn't get the
>>> impression that all or even most of the macro techniques were
>>> unhygienic. 
>> 
>> 
>> Hygiene is a technical term. The idea is roughly that 
>> the __macro system__ (as a whole) should respect the 
>> lexical structure of your program. That is, by default
>> no programmer should be able to accidentally write a 
>> macro that messes up lexical bindings in a subtle way. 
> 
> Dave Herman mentioned this to me some time ago, and my immediate response was 
> this: okay, if the term "hygiene" refers to a macro system and not to a 
> macro, then *what word* should we use to describe macros that violate 
> transparency? "non-transparent"?
> 
> John
> 
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Is there anything like the cl format?

2010-12-17 Thread Richard Cleis
Someone on this list, several years ago, wrote scheme functions that  
were similar to C/printf/formats.  I don't have time to look for the  
files right now, but they might do everything you want.


RAC

On Dec 17, 2010, at 4:30 AM, Manfred Lotz  wrote:


On Fri, 17 Dec 2010 11:09:04 +0100
Laurent  wrote:


You probably want
`real->decimal-string

'

Maybe it would be a good idea in the `format' page to add a pointer
to that function?



Yeah, I used it. However, it isn't nice to code, and it is not quite
the same.

Compare

; if it were available
(printf "Total:  %4.2f/%2.2f   %4.2f/%2.2f\n" fnum1 fnum2 fnum3 fnum4)

to this:
(let ([pfnum1 (real->decimal-string fnum1 2)]
 [pfnum2 (real->decimal-string fnum2 2)]
 [pfnum3 (real->decimal-string fnum3 2)]
 [pfnum4 (real->decimal-string fnum4 2)])
 (printf "Total: ~a/~a  ~a/~a" pfnum1 pfnum2 pfnum3 pfnum4))


--
Manfred



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

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


Re: [racket] Am I Missing Something? [HtDP 31.3.1]

2011-01-04 Thread Richard Cleis
I can explain it, but I don't know if it's revealing a solution.

rac

On Jan 4, 2011, at 12:32 PM, Stephen Chang wrote:

> I get results similar to Carl.
> 
> Welcome to DrRacket, version 5.0.1.7 [3m].
> Language: Intermediate Student.
> #i-0.49746596003269394
> #i-0.4974659600326953
> #i-4974659600326939.0
> #i-4974659600326953.0
>> (equal? (sum (g-series #i1000)) (accu-sum (g-series #i1000)))
> false
>> (equal? (* 10e15 (sum (g-series #i1000))) (* 10e15 (accu-sum (g-series 
>> #i1000
> false
>> 
> 
> 
> Luke, can you post the output you get?
> 
> 
> 
> 
> On Tue, Jan 4, 2011 at 10:57 AM, Carl Eastlund  wrote:
>> 
>> On Tue, Jan 4, 2011 at 9:38 AM, Luke Jordan  wrote:
>>> All that code came straight out of the text, except that I used if instead
>>> of cond.  The sum, accu-sum, and g-series defs are all given.  In your
>> 
>> Ah, yes, now I see where the accumulator-based sum is.  Sorry, my mistake.
>> 
>>> results I see a difference.  When I run it at home it's the same.  I can
>>> even (equal? (sum (listof number)) (accu-sum (listof number))) and get true.
>> 
>> No idea what's going on.  Maybe someone else will have an idea.
>> 
>> --Carl
>> _
>> For list-related administrative tasks:
>> http://lists.racket-lang.org/listinfo/users
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Am I Missing Something? [HtDP 31.3.1]

2011-01-04 Thread Richard Cleis
Oops. Sorry.  I was interpreting the issue backwards. I don't have an 
explanation; Luke needs to show his numbers. Or I need to be in the lab where I 
can run it on Ubuntu, which doesn't seem likely to be the issue anyway.

rac

On Jan 4, 2011, at 1:26 PM, Carl Eastlund wrote:

> Richard,
> 
> We're not looking for an explanation of why the two numbers are
> different.  We're looking for an explanation of why, on Luke's
> machine, unlike anybody else's here, they _aren't_ different.  Somehow
> I don't think portability issues in DrRacket are anybody's homework
> assignment.  So if you have an explanation, please share.  :)
> 
> Carl Eastlund
> 
> On Tue, Jan 4, 2011 at 3:22 PM, Richard Cleis  wrote:
>> I can explain it, but I don't know if it's revealing a solution.
>> 
>> rac
>> 
>> On Jan 4, 2011, at 12:32 PM, Stephen Chang wrote:
>> 
>>> I get results similar to Carl.
>>> 
>>> Welcome to DrRacket, version 5.0.1.7 [3m].
>>> Language: Intermediate Student.
>>> #i-0.49746596003269394
>>> #i-0.4974659600326953
>>> #i-4974659600326939.0
>>> #i-4974659600326953.0
>>>> (equal? (sum (g-series #i1000)) (accu-sum (g-series #i1000)))
>>> false
>>>> (equal? (* 10e15 (sum (g-series #i1000))) (* 10e15 (accu-sum (g-series 
>>>> #i1000
>>> false
>>>> 
>>> 
>>> 
>>> Luke, can you post the output you get?
>>> 
>>> 
>>> 
>>> 
>>> On Tue, Jan 4, 2011 at 10:57 AM, Carl Eastlund  wrote:
>>>> 
>>>> On Tue, Jan 4, 2011 at 9:38 AM, Luke Jordan  wrote:
>>>>> All that code came straight out of the text, except that I used if instead
>>>>> of cond.  The sum, accu-sum, and g-series defs are all given.  In your
>>>> 
>>>> Ah, yes, now I see where the accumulator-based sum is.  Sorry, my mistake.
>>>> 
>>>>> results I see a difference.  When I run it at home it's the same.  I can
>>>>> even (equal? (sum (listof number)) (accu-sum (listof number))) and get 
>>>>> true.
>>>> 
>>>> No idea what's going on.  Maybe someone else will have an idea.
>>>> 
>>>> --Carl

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


Re: [racket] Am I Missing Something? [HtDP 31.3.1]

2011-01-04 Thread Richard Cleis
Can you post the first few dozen elements of g-series?

rac

On Jan 4, 2011, at 1:41 PM, David Van Horn wrote:

> On 1/4/11 3:26 PM, Carl Eastlund wrote:
>> We're not looking for an explanation of why the two numbers are
>> different.  We're looking for an explanation of why, on Luke's
>> machine, unlike anybody else's here, they _aren't_ different.
> 
> FWIW, I see Luke's behavior using 5.0.2 on login.ccs.neu.edu.
> 
> The numbers I get in DrRacket/ISL+:
> 
> #i-0.49746596003269405
> #i-0.49746596003269405
> #i-4974659600326941.0
> #i-4974659600326941.0
> 
> Linux login 2.6.31-22-generic #60-Ubuntu SMP Thu May 27 00:22:23 UTC 2010 
> i686 GNU/Linux
> 
> On the other hand, I get different numbers using 5.0.2 on my own machine.
> 
> #i-0.4974659600326926
> #i-0.49746596003269405
> #i-4974659600326926.0
> #i-4974659600326941.0
> 
> Darwin doom.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 
> PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386
> 
> David
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Am I Missing Something? [HtDP 31.3.1]

2011-01-04 Thread Richard Cleis
I wonder if it has something to do with the rounding switches in fenv.h.  For 
example, the last elements are:

 -6.137094160310568e-05
 -6.13709416031052e-05

The precision is different, and if the higher precision representation is 
rounded to the lower one, the 15th digit differs by 5.

rac

On Jan 4, 2011, at 2:04 PM, David Van Horn wrote:

> On 1/4/11 3:55 PM, Richard Cleis wrote:
>> Can you post the first few dozen elements of g-series?
> 
> Ubuntu (Luke's behavior):
> 
> Welcome to Racket v5.0.2.
> > (define (g-series n)
>(if (zero? n)
>empty
>(cons (expt -0.99 n) (g-series (sub1 n)
> > (take (g-series #i1000) 36)
> (4.317124741065751e-05
> -4.360732061682577e-05
> 4.404779860285432e-05
> -4.449272586146901e-05
> 4.4942147334817175e-05
> -4.539610841900725e-05
> 4.5854654968694194e-05
> -4.631783330171131e-05
> 4.6785690203748796e-05
> -4.7258272933079593e-05
> 4.773562922533292e-05
> -4.8217807298316076e-05
> 4.8704855856884935e-05
> -4.9196824097863566e-05
> 4.969376171501371e-05
> -5.019571890405425e-05
> 5.0702746367731566e-05
> -5.1214895320940976e-05
> 5.173221749589997e-05
> -5.2254765147373715e-05
> 5.278259105795324e-05
> -5.331574854338711e-05
> 5.3854291457966793e-05
> -5.439827419996645e-05
> 5.494775171713783e-05
> -5.550277951226043e-05
> 5.606341364874792e-05
> -5.662971075631102e-05
> 5.7201728036677816e-05
> -5.777952326937152e-05
> 5.836315481754699e-05
> -5.895268163388586e-05
> 5.954816326655136e-05
> -6.014965986520341e-05
> 6.075723218707414e-05
> -6.13709416031052e-05)
> 
> My mac (expected behavior):
> 
> [Q: Is this a PPC?  A: Nope.]
> 
> Welcome to Racket v5.0.2.
> > (define (g-series n)
>(if (zero? n)
>empty
>(cons (expt #e-0.99 n) (g-series (sub1 n)
> > (take (g-series #i1000) 36)
> '(4.317124741065786e-05
>  -4.360732061682612e-05
>  4.404779860285467e-05
>  -4.449272586146937e-05
>  4.494214733481754e-05
>  -4.539610841900762e-05
>  4.585465496869457e-05
>  -4.631783330171168e-05
>  4.6785690203749175e-05
>  -4.725827293307997e-05
>  4.77356292251e-05
>  -4.821780729831647e-05
>  4.870485585688533e-05
>  -4.9196824097863966e-05
>  4.969376171501411e-05
>  -5.019571890405466e-05
>  5.070274636773198e-05
>  -5.121489532094139e-05
>  5.173221749590039e-05
>  -5.2254765147374135e-05
>  5.2782591057953676e-05
>  -5.3315748543387546e-05
>  5.385429145796722e-05
>  -5.4398274199966894e-05
>  5.494775171713828e-05
>  -5.5502779512260884e-05
>  5.606341364874837e-05
>  -5.662971075631149e-05
>  5.720172803667826e-05
>  -5.777952326937199e-05
>  5.8363154817547464e-05
>  -5.8952681633886325e-05
>  5.954816326655184e-05
>  -6.014965986520388e-05
>  6.0757232187074635e-05
>  -6.137094160310568e-05)
> 
> David

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


Re: [racket] Am I Missing Something? [HtDP 31.3.1]

2011-01-04 Thread Richard Cleis
I wonder if Babbage had any idea how much trouble he was starting.

rac

On Jan 4, 2011, at 3:13 PM, Matthew Flatt wrote:

> At Tue, 4 Jan 2011 14:39:39 -0700, Matthew Flatt wrote:
>> Racket sets the x87 control word to use double precision instead of
>> extended precision. That setting apparently interferes with the pow()
>> C library function.
> 
> The following page suggests that the problem is relatively specific to pow():
> 
> http://www.vinc17.org/research/extended.en.html
> 
> (That page is cited in a context similar to ours at
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16122)
> 
> For now, anyway, I don't have a better solution than resetting the FP
> mode back to extended precision before calling pow() under Linux.
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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


Re: [racket] string-trim : an implementation & a question

2011-04-02 Thread Richard Cleis
You can use an index to the string to find the location of your goal, then 
return the substring when you are done.

rac

On Apr 2, 2011, at 3:08 PM, Charles Hixson wrote:

> This seems to be what I want the string-trim to do, but it seems that all the 
> string copying would be expensive.  Is there a way to improve it by avoiding 
> the string copying?
> 
> My original inclination was to use a while loop with a test for 
> non-whitespace, but that appears to not be something scheme supports.
> 
> (define (string-trim s)
>(let ( (l (string-length s) ) )
>  (cond
>[ (= l 0) #f]
>[ (char-whitespace? (string-ref s (- l 1) ) )(string-trim 
> (substring s 0 (- l 1) ) ) ]
>[else s]) ) )
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Printing multiple stmts in cond

2011-04-29 Thread Richard Cleis
You can return more than one by forming a list, or by using something like 
(values val-1 val-2 ...)

rac

On Apr 29, 2011, at 11:45 PM, nikhil wrote:

> Hi,
> 
> I am new to Racket so please bear with me. I am trying to print multiple 
> expressions in "cond" statement as below.
> 
> 
> (let ((var `(make))
> 
> (exp '(1 2)))
> 
> (cond
> 
>   [(number? 2) `(hi ,var)
> 
>   `(bye ,exp)]))
> 
> 
> 
> 
> But only the "bye" statement is returned/printed on the screen. The first 
> "hi" is not evaluated at all. How do I return/print both ?
> 
> Thanks
> 
> 
> 
> Nik
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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

Re: [racket] Printing multiple stmts in cond

2011-04-30 Thread Richard Cleis

On Apr 30, 2011, at 12:52 AM, nikhil wrote:

> What you guys suggest solves the problem of returning multiple values. Since 
> I havent provided any context, my original problem still exists. Sorry about 
> that.
> 
> This is what I was trying to do,
> 
> (if (condition?) 
>  (stmt1))
> 
> (if (condition?)
>  (stmt2)
>  (stmt3))
>
> In the first if condition(stmt1), I have no else condition. Since this is not 
> allowed, I used (cond ...)

For conditionals with only one clause, use (when ... ...) or (unless ... ...)

> Basically, I dont want to execute an else stmt or return multiple values. I 
> just want to return "stmt1" if condition satisfies and dont do anything if 
> false. No returning # or anything.
> 
> Am I making any sense ? if yes, is it possible ? 
> 

> 

What does it mean, to return nothing? 'if' will return the results of one of 
it's two clauses. However, a when statement will either return the result of 
it's only clause or something that represents nothing: void. A program can 
check for the result of void like any other value.


rac

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


Re: [racket] Printing multiple stmts in cond

2011-04-30 Thread Richard Cleis
(if (condition? data)
(FF x1 x2 xNEW x3 x4)
(f x1 x2 x3 x4))

The result of one of them is returned.

rac


On Apr 30, 2011, at 1:16 AM, nikhil wrote:

> Ok. Here's what I am trying to do.
> 
> I am parsing incoming racket code and generating back racket code. 
> 
> In my case, I have an incoming function which takes 4 arguments and I need to 
> generate a function which takes in 5 args when a condition satisfies, if not 
> then the original 4 args .
> 
> Something like,
> 
> Input--> 
> (f x1 x2 x3 x4)
> 
> Output-->
> (FF x1 x2 xNEW x3 x4)
> 
> --
> 
> (define (parse-func exp)
>(cond
> 
> 
>[(f? exp)
>`(FF
>  ,x1
>  ,x2
>  ,(if (condition?)
>   xNEW)
>
>  ,x3
>  ,x4)]
> 
> (The above is just pseudo-code) As shown above, when the if condition fails I 
> just want 4 args. But a default # is passed instead when used with 
> cond. 
> 
> I am new to racket and functional programing in general, so I am not able to 
> express my problem very accurately :(
> Hope the above example is clear enough to explain what I am doing. 
> 
> 
> 
> On Sat, Apr 30, 2011 at 7:00 AM, Neil Van Dyke  wrote:
> nikhil wrote at 04/30/2011 02:52 AM:
> 
> Basically, I dont want to execute an else stmt or return multiple values. I 
> just want to return "stmt1" if condition satisfies and dont do anything if 
> false. No returning # or anything.
> 
> An expression always produces at least one value, even if the value is the 
> void value.  (Usually, a REPL will hide a returned void value from you, but a 
> void value is still being returned, which can be confusing.)
> 
> If you can show *why* you don't want to produce *any* value, then people can 
> show you different ways to write that code.
> 
> -- 
> http://www.neilvandyke.org/
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

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

Re: [racket] Getting started with R6RS

2011-05-14 Thread Richard Cleis
I like the #lang format, but it doesn't work when I embed 5.0 in C programs. 
The 'modules' format works fine. Am I doing something wrong?

rac

On May 14, 2011, at 8:32 PM, Eli Barzilay wrote:

> Two hours ago, Shriram Krishnamurthi wrote:
>> 
>> Much the same as, when I used to write lots of shell programs, I
>> didn't really think about writing a #! on the first line, until
>> there was some reason to know how the file was being interpreted, at
>> which point I was glad I could just read it off the first line.
>> 
>> #lang is just #! done right.  Maybe it should be presented that way.
>> (And then the Windows weenies will ask, "What's #!?"...)
> 
> That's a *really* good analogy.  It determines the language in a
> similar way, and it's magical in a similar way.  (That is, trying to
> understand how it works involves obscure kernel level hacks for how
> these files are considered executables, how they're being executed,
> etc.)
> 
> Making this analogy would probably be very useful for Elliott's case,
> but even if you ignore the windows crowd I think that too few people
> know about it enough to make it effective.
> 
> -- 
> ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
>   http://barzilay.org/   Maze is Life!
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] Temporary Definitions with ellipses

2011-05-24 Thread Richard Cleis
You need to write a little more content.  For example

(define (feet->yards f)
   (define ... "this will be yards") ...)

RAC

On May 24, 2011, at 8:25 AM, SCIAMACHIST  wrote:

> Lewis Watmore
> 
> Hello,
>I am a "noob" so if this is the wrong place for my question, please direct 
> me to somewhere more appropriate.
> 
>In the DrScheme Companion at "3.3 Finger Exercises on Composing Functions" 
> it is stated that you can create temporary definitions using an ellipsis in 
> this manor:
> 
>(define (feet->yards f) ...)
> 
> --where the ellipsis "is a legal Scheme name. DrScheme does not attempt to 
> determine the meaning of a name until necessary."
> 
> But DrRacket does not allow this usage. I get this error message: "...: 
> ellipses not allowed as an expression in: (...)"
>Is there an alternative other than commenting-out unfinished definitions?
> 
> Thanks
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] print bigger text?(message label)

2011-05-26 Thread Richard Cleis
I am not quite sure what you are asking, but you can try the following after 
checking the docs for font% message% and button% ...

(define trial-font (make-object font% 24 'default))

...

(define s (new message% (label "sentence") (parent f) (font trial-font)))

...

I just met a Korean woman, so your program could be useful to me :)

rac



On May 26, 2011, at 1:44 AM, 김태윤 wrote:

> hello
> I made a simple english learning program
> in text text file, korean and english slash saperated pair stored in each line
> it's kind of quiz game
> but the problem is that
> I can't size up the message label
> do I have to use graphical way?
> or is there any easy way I can print bigger text?
> thanks in advanced
> 
> #lang racket/gui
> (define answer 0)
> (define (cbs b e)
>  (set! select (random items))
>  (send s set-label
>(list-ref data select)))
> (define (cba b e)
>  (if (even? select)
>  (set! answer (+ 1 select))
>  (set! answer (- 1 select)))
>  (set! answer (abs answer))
>  (send a set-label
>(list-ref data answer))
> 
>  )
> (define f (new frame% (label "Duplex English Learner") (min-width 320)
> (min-height 60)))
> (define bs (new button% (label "sentence") (parent f) (callback
> (lambda (b e) (cbs b e)
> (define ba (new button% (label "answer") (parent f) (callback (lambda
> (b e) (cba b e)
> (define s (new message% (label "sentence
> ") (parent f)))
> (define a (new message% (label "answer
> ") (parent f)))
> (send f show #t)
> (define path
>  (get-file "utf-8 text only"  
>#f
>#f
>"utf-8 text only"))
> (define port (open-input-file path))
> (define data '())
> (define (load [line (read-line port)])
>  (when (not (eof-object? line))
>(set! data (append data
>   (regexp-match* #rx"[^/\r]+" line)))
>(load)))
> (load)
> (define items (length data))
> (define select 0)
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users


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

Re: [racket] in praise of if's mandatory else clause

2011-05-29 Thread Richard Cleis

On May 29, 2011, at 8:01 PM, Grant Rettke  wrote:

> On Sun, May 29, 2011 at 1:17 AM, Neil Van Dyke  wrote:
>> Doing it manually turned out to be fortunate, since Racket has
>> already found *five* independent (i.e., not copy&pasted) locations where the
>> programmers clearly intended to do "(if B E1 E2)", but instead did something
>> else, usually "(if B E1) E2".  I won't be surprised if I find a few more by
>> the time all the code compiles.
> 
> One of the few code inspections that we do on the CI server for our
> Java and .NET systems (virtually all of our billable work) is to
> forbid one-armed if statements; they are always a source of trouble.
> 
I had been converting every 'if' I see from my early days of scheming, into 
'cond.' The else-enforcement now makes 'if' acceptable, but I sometimes still 
prefer cond, when, and unless due to the implied-begin consistency in all 
three... and the overt possibility of void returns in the latter two.

Can you effectively forbid programming constructs in your programming group? 
From what planet do they hail? :)

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

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


Re: [racket] in praise of if's mandatory else clause

2011-05-30 Thread Richard Cleis

On May 30, 2011, at 2:25 PM, Ian Barland wrote:

>> forbid one-armed if statements; they are always a source of trouble.
>> 
> FWIW, this link appeals to some students, about the perils of one-armed-if:
> 
> http://www.zuneboards.com/forums/zune-news/38143-cause-zune-30-leapyear-problem-isolated.html
> 
> --Ian

I see a more important message in that example:

Those who claim that functional programming is hard to read, often write code 
as in that example (I am a veteran of that sort of programming; I can't be the 
only one.) Even though it is supposedly easy to read, it is not easy to discern 
that it is wrong. An HtDP solution would more likely describe the data first 
(days are less than 366, equal to 366, or greater than 366). One cond would 
handle all three, two would terminate, and the the last would continue the 
accumulation. 

In other words, the possibility of that hard-to-read bug doesn't exist.

rac



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


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


Re: [racket] in praise of if's mandatory else clause

2011-05-30 Thread Richard Cleis
Buggy loops can also be avoided by reducing the problem.  These leap-year cases 
are less troubling if the function that really matters is used: the days in a 
given year.

(define (days-in-year year) (if (= 0 (remainder year 4)) 366 365))

(define (yr-da yr da)
  (cond  ((<= da (days-in-year yr)) (values yr da)) ; Done: da is 
within the year, yr.
 (else (yr-da (+ 1 yr) (- da (days-in-year yr)) ; reduce da by days 
in the year, yr.

A little rearranging can remove the inefficiency of computing days-in-a-year 
twice.

But how would I arrive at that solution by using the blue book?

rac


On May 30, 2011, at 8:31 PM, Matthias Felleisen wrote:

> 
> On May 30, 2011, at 9:11 PM, Richard Cleis wrote:
> 
>> An HtDP solution would more likely describe the data first (days are less 
>> than 366, equal to 366, or greater than 366). One cond would handle all 
>> three, two would terminate, and the the last would continue the 
>> accumulation. 
> 
> I had actually written the program in HtDP style, and yes, the accumulator 
> made it clear that the if was wrong: 
> 
> ;; N -> [List N N N] 
> (define (my-date days)
>  ;; N N -> N 
>  ;; accu: y is the number of complete years between days and d, plus 1980
>  ;; gen. recursion (subtract number of days until the number is w/i a year)
>  (define (year d y)
>(cond
>  [(<= d 365) (values y d)]
>  [else (if (leap-year? y) 
>(cond
>  [(> d 366) (year (- d 366) (+ y 1))]
>  [(= d 366) (values y d)])
>(year (- d 365) (+ y 1)))]))
>  (define-values (the-year remaining-days-in-year) (year days 1980))
>  ;; N N -> N 
>  ;; accu: m is the months between remaining-days-in-year and d, starting in 
> Jan
>  ;; gen. recursion (subtract number of days until w/i a month) 
>  (define (month d m)
>(cond
>  [(<= d (month->days m the-year)) (values m d)]
>  [else (month (- d (month->days m the-year)) (+ m 1))]))
>  (define-values (the-month remaining-days-in-month) (month 
> remaining-days-in-year 1))
>  ;; -- IN -- 
>  (list the-year the-month remaining-days-in-month))
> 
> ;; N -> Boolean 
> ;; simplistic definition 
> (define (leap-year? y)
>  (= (remainder y 4) 0))
> 
> ;; N N -> N 
> ;; the number of days in month m for year y 
> (define (month->days m y)
>  (case m 
>[(1 3   5   7 8   10 12) 31]
>[(4   6 9 11)30]
>[else (if (leap-year? y) 29 28)]))
> 
> ;; -- testing --- 
> 
> (check-equal? (my-date 364) '(1980 12 29))
> (check-equal? (my-date 366) '(1980 12 31))
> (check-equal? (my-date (+ 365 366)) '(1981 12 31))
> (check-equal? (my-date (+ 365 365 365 366)) '(1983 12 31))
> 
> (define long 
>  (let ([years# (- 2009 1980)])
>(apply + (build-list years# (lambda (i) (define y (+ i 1980)) (if 
> (leap-year? y) `366 365))
> 
> (check-equal? (my-date long) '(2008 12 31))
> 
> 
>> In other words, the possibility of that hard-to-read bug doesn't exist.
> 
> There are bugs in FP programs for sure, but the [while-]loop  exit bugs 
> disappear. 
> 
> 


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


Re: [racket] disable garbage collection

2011-06-02 Thread Richard Cleis
I have ruled out Racket in applications were I needed to precisely inhibit GC 
until regular critical slices are completed, then trigger GC ASAP.  The efforts 
were partially successful, but there's no way to guarantee behavior of faux 
real-time hacks like that.

I wonder how difficult it would be to have randomly interruptible GC.  It seems 
impossible, but I would use it.  The Impossible is often desirable.

RAC

On Jun 2, 2011, at 10:01 AM, Eduardo Bellani  wrote:

>> * Extremely Unusual Situations: if you're in the unusual situation of
>> doing something normally considered inadvisable, like you're
>> intentionally designing the SR-71 to leak fuel, maybe there's some
>> bizarre rocket-scientist reason understood only by you that you have to
>> turn off GC just to get your app to fly in one piece.  Almost no one
>> will ever need this, and, in the case of Racket, they could always add
>> it if they did.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] disable garbage collection

2011-06-02 Thread Richard Cleis

On Jun 2, 2011, at 1:46 PM, Stephen Bloch wrote:

> 
> On Jun 2, 2011, at 3:35 PM, Neil Van Dyke wrote:
> 
>> Good points.  For my list of reasons, I was thinking only of disabling GC 
>> for the lifetime of a process, but there are additional reasons that one 
>> might want to temporarily inhibit GC for a shorter duration.
> 
> An even simpler thing to do, which won't give you hard-real-time guarantees 
> but will work most of the time, is to allow the programmer to say "Please 
> garbage-collect NOW" just BEFORE a time-critical section of code.  I could 
> have sworn there used to be a (gc) function that did this, but it doesn't 
> seem to work in 5.1.

In some of my cases, the process prepares for a small number of operations 
which it eventually executes on a precise hack. The ordering would be: hack, 
execute limited critical operations, prepare for the next hack (the bulk of the 
processing), gc, wait for the next hack (via interrupt, select, whatever).  If 
I were a real researcher with a real budget, investigating the limitations of 
that sort of thing would be high on my list. I have many ideas for control 
systems that will never be attempted, because hard-hacking in C is tedious and 
de-motivational. Fine software tools are available but they discourage, if not 
prevent outright, thinking out of the box.

rac

> 
> 
> Stephen Bloch
> sbl...@adelphi.edu
> 
> 
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users

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


Re: [racket] find-seconds, second : (integer-in 0 61)

2011-06-03 Thread Richard Cleis
I do precise accurate stuff with Racket, because it syncs current-ms with 
external time sources.  Ironically, the environments that overtly fuss over 
human issues like leap seconds are the environments that *cannot* be used.

RAC

On Jun 3, 2011, at 6:47 PM, "Geoffrey S. Knauth"  wrote:

> Just curious.  The contact for find-seconds parameter second (integer-in 0 
> 61) instead of (integer-in 0 59). [1]
> 
> The Java definition of a Date [2] states "the values 60 and 61 occur only for 
> leap seconds and even then only in Java implementations that actually track 
> leap seconds correctly," which made me wonder if the values 60 or 61 were 
> actually used by Racket.  According to [3], we've had one leap second at the 
> end of 2005 and 2008.  Does any PLT Scheme or Racket code actually track or 
> use those leap seconds?  I guess if I were using Racket to fire reverse 
> thrusters for re-entry on the space shuttle, I might want to know, since the 
> shuttle moves along at six miles per second.
> 
> Geoff
> 
> [1] Reference:Racket § 14.6 Time
> [2] http://download.oracle.com/javase/7/docs/api/java/util/Date.html
> [3] http://en.wikipedia.org/wiki/Leap_second
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Gambit Scheme for the iPhone and iPad

2011-06-04 Thread Richard Cleis

On Jun 4, 2011, at 7:55 PM, Nevo  wrote:

> Hi Prabhakar!
>   This is a nice sharing. Have you by chance bought that app and actually run 
> on your iPhone/iPad? I just wonder whether this is console based REPL only,

It has an editor that allows for multiple 'scripts'.  When one is run, the 
environment drops into a repl.

(edit) returns to the multiple script view.

One of the examples is a webview that apparently supports HTML output. I don't 
know how extensively; I just now downloaded it at this party.  I'm oozing 
geekiness beyond acceptable levels.

(exit)

> or having graphics support as DrRacket does, how is the performance (pure 
> interpreter mode or JIT enabled?). I'm not clear if Apple actually ever has 
> explicitly restricted applications bundled with a programming language 
> interp, but they seems disallowing application to download *script* or other 
> executable files from other places. I think we can provide a DrRacket like 
> programming/educating/developing environment. MonoTouch is a good example to 
> run another programming runtime over the native platform.
> 
> - nevo
> 
> On 5 June 2011 06:15, Prabhakar Ragde  wrote:
> I stopped reading comp.lang.scheme some time ago, so I wasn't aware until 
> just now that in early May, Marc Feeley succeeded in placing a Gambit Scheme 
> universal app (iPhone/iPad) in the App Store.
> 
> http://itunes.apple.com/us/app/gambit-repl/id434534076?mt=8
> 
> This is the first indication I had that Apple had relaxed their App Store 
> restrictions sufficiently to permit real programming language interpreters. I 
> thought others on this list might be interested in knowing this fact. --PR
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] `'unquote -- error or not?

2011-07-07 Thread Richard Cleis
I don't get it.  The quotes are conveniences.  If they are not convenient, why 
can't you merely list what you want?

(list '... ''unquote '...)

rac

On Jul 7, 2011, at 8:33 AM, Bas Steunebrink wrote:

> Thanks for the fast answers!
> Actually I wanted to get 'unquote inside of a quasiquote; I'm now using:
> `(... ,''unquote ...)
> It ain't pretty but it appears to do the job! :-)
> 
> Bas
> 
> 
> On 7/7/11 16:20 PM, Robby Findler wrote:
>> FWIW, I'm right in line with this rationale.
>> 
>> Robby
>> 
>> On Thu, Jul 7, 2011 at 9:13 AM, Matthias Felleisen  
>> wrote:
>>> 
>>> On Jul 7, 2011, at 10:01 AM, Bas Steunebrink wrote:
>>> 
 Ciao a tutti,
 
 When I type `'unquote in DrRacket, an error is thrown:
 
> `'unquote
 (X) unquote: expects exactly one expression in: (unquote)
 
 I understand why this error occurs from the way quasiquote is expanded; 
 see e.g. http://community.schemewiki.org/?scheme-faq-language#qqmacro (I 
 guess DrRacket works similarly). Still, I feel the result should be just 
 'unquote. What do you think?
>>> 
>>> No, your use of backquote explicitly calls for a search for unquote.
>>> 
>>> If you want the symbol unquote inside of an unquote, you first need to 
>>> unquote:
>>> 
 `,'unquote
>>> unquote
>>> 
>>> (as in comma = unquote).
>>> _
>>>  For list-related administrative tasks:
>>>  http://lists.racket-lang.org/listinfo/users
>>> 
> _
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users


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


  1   2   >