Re: [racket-users] Positioning GUI controls in contact with one another

2016-09-05 Thread Robby Findler
I haven't seen buttons in spreadsheet cells in excel, but maybe I'm
taking your words too literally?

Have you considered using canvas% objects instead of buttons? They
should give you the flexibility you're after.

Robby

On Mon, Sep 5, 2016 at 4:23 PM, David Storrs  wrote:
> How do I find the actual minimum size of a GUI control (e.g. a button)
> without the space around it?
>
>
> I'm on OSX 10.11.  I'm working on a spreadsheet application, and my current
> plan is to have each cell be represented as a separate text control.[1]  I
> need to have these controls be in contact with one another the way they are
> in Excel or any other spreadsheet.  (That is, there is no empty space
> between the controls.) By default Racket wants to put significant space
> between controls and I've been unable to figure out how to stop this in a
> clean, cross-platform way.
>
> Here's what I've tried:
>
> (define frame (new frame% [label "Example"]))
> (define panel (new horizontal-panel% [parent frame]))
> (define left-btn (new button% [parent panel] [label "Left"]))
> (define right-btn (new button% [parent panel] [label "Right"]))
> (define (shrinkwrap c)
>   (send c horiz-margin 0)
>   (send c vert-margin 0))
> (void (map shrinkwrap (list left-btn right-btn panel)))
> (for ((c (list panel frame)))
>  (send c spacing 0))
> ;;These won't work because get-min-graphical-size is 84 and will trump
> the requested size
> (send left-btn min-width 70)
> (send right-btn min-width 70)
>
> (send frame show #t)
>
> This shows the frame with two buttons arranged horizontally.  There is
> significant space around each button and between the two buttons.  I want
> there to be no space between them.
>
>
> Both the left and right buttons have minimum graphical sizes of (84,32), as
> shown by:
> (begin
>   (define-values (w h) (send left-btn get-graphical-min-size))
>   (displayln
>(format "left button min w/h: ~a,~a" w h)))
> ;; Same for right-btn
>
> A quick test shows that I can get the behavior I need by overriding
> place-children:
>
> (define squishable-panel%
>   (class horizontal-panel%
>  (define/override (place-children info w h)
>(displayln "Called place-children")
>'((0 0 70 20) (70 0 70 20)))
>  (super-new)))
> (define panel (new squishable-panel% [parent frame]))
> ;;  ...all other declarations stay the same...
>
> The problem is that I got the above numbers by experimentation.
> get-graphical-min-size returns the size *with* the spacing that I'm trying
> to get rid of, which defeats the purpose.  (Also, why??  That's not the size
> of the button, it's the size of the button plus some extra space.)  I don't
> see a clean way to go from the GMS to the actual minimum size when dealing
> with cross-platform size differences and the fact that Windows is
> pixel-based and OSX is drawing-unit-based.
>
> Any suggestions?
>
>
> Dave
>
> [1] I may need to do some optimizations later instead of representing empty
> cells as controls, but that's for later.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Positioning GUI controls in contact with one another

2016-09-05 Thread David Storrs
How do I find the actual minimum size of a GUI control (e.g. a button)
without the space around it?


I'm on OSX 10.11.  I'm working on a spreadsheet application, and my current
plan is to have each cell be represented as a separate text control.[1]  I
need to have these controls be in contact with one another the way they are
in Excel or any other spreadsheet.  (That is, there is no empty space
between the controls.) By default Racket wants to put significant space
between controls and I've been unable to figure out how to stop this in a
clean, cross-platform way.

Here's what I've tried:

(define frame (new frame% [label "Example"]))
(define panel (new horizontal-panel% [parent frame]))
(define left-btn (new button% [parent panel] [label "Left"]))
(define right-btn (new button% [parent panel] [label "Right"]))
(define (shrinkwrap c)
  (send c horiz-margin 0)
  (send c vert-margin 0))
(void (map shrinkwrap (list left-btn right-btn panel)))
(for ((c (list panel frame)))
 (send c spacing 0))
;;These won't work because get-min-graphical-size is 84 and will trump
the requested size
(send left-btn min-width 70)
(send right-btn min-width 70)

(send frame show #t)

This shows the frame with two buttons arranged horizontally.  There is
significant space around each button and between the two buttons.  I want
there to be no space between them.


Both the left and right buttons have minimum graphical sizes of (84,32), as
shown by:
(begin
  (define-values (w h) (send left-btn get-graphical-min-size))
  (displayln
   (format "left button min w/h: ~a,~a" w h)))
;; Same for right-btn

A quick test shows that I can get the behavior I need by overriding
place-children:

(define squishable-panel%
  (class horizontal-panel%
 (define/override (place-children info w h)
   (displayln "Called place-children")
   '((0 0 70 20) (70 0 70 20)))
 (super-new)))
(define panel (new squishable-panel% [parent frame]))
;;  ...all other declarations stay the same...

The problem is that I got the above numbers by experimentation.
get-graphical-min-size returns the size *with* the spacing that I'm trying
to get rid of, which defeats the purpose.  (Also, why??  That's not the
size of the button, it's the size of the button plus some extra space.)  I
don't see a clean way to go from the GMS to the actual minimum size when
dealing with cross-platform size differences and the fact that Windows is
pixel-based and OSX is drawing-unit-based.

Any suggestions?


Dave

[1] I may need to do some optimizations later instead of representing empty
cells as controls, but that's for later.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: DrRacket on OpenBSD 6.0

2016-09-05 Thread Juan Francisco Cantero Hurtado

On 02/09/16 13:08, Philippe Meunier wrote:

Hello,

FYI, W^X is now more strictly enforced on OpenBSD so DrRacket is not
going to work anymore be default:
https://marc.info/?l=openbsd-misc=147273821220405

"We are pleased to announce the official release of OpenBSD 6.0.
[...]
 - Security improvements:
 o W^X is now strictly enforced by default; a program can only
   violate it if the executable is marked with PT_OPENBSD_WXNEEDED
   and is located on a filesystem mounted with the wxallowed mount(8)
   option. Because there are still too many ports which violate W^X,
   the installer mounts the /usr/local filesystem with wxallowed.
   This allows the base system to be more secure as long as
   /usr/local is a separate filesystem. If you use no W^X violating
   programs, consider manually revoking that option."

The PT_OPENBSD_WXNEEDED part means that executables need to be linked
using ld's -z wxneeded option (which is new and does not work in
previous versions of OpenBSD): http://man.openbsd.org/OpenBSD-current/man1/ld.1


The best advice is always: "install racket-minimal and follow the 
instructions in the pkg-readme" :) . I test the package regularly on 
amd64, i386, macppc and sparc64. DrRacket is also tested on amd64 and 
i386 (unfortunately, it doesn't work on macppc and sparc64).


For people building racket from the tarball:
- mount the filesystem with the option wxallowed
- decompress the tarball
- cd src
- LDFLAGS="-Wl,-z,wxneeded" ./configure
- make
- make install

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] syntax-parse in typed racket

2016-09-05 Thread Matthias Felleisen

The easiest and proper fix is to write typed macros for typed modules. Below is 
a naive but straightforward solution. It would be better if define-memoized 
fished out the type declaration for f and used it to add domain types for 
arg-s...

#lang typed/racket

(require (for-syntax syntax/parse))

(: memoize (All (r a ...)
(-> (-> a ... a r)
(-> a ... a r
(define (memoize fn)
  (let ([store : (HashTable Any r) (make-hash)])
(define (memfn . [args : a ... a])
  (hash-ref store args
(lambda ()
  (let ([result : r (apply fn args)])
(hash-set! store args result)
result
memfn))

(: fibo (-> Integer Integer))
(define fibo (memoize (lambda ([n : Integer])
(if (<= n 1)
1
(+ (fibo (- n 1))
   (fibo (- n 2)))

(define-syntax (define-memoized stx)
  (syntax-parse stx ;; I didn’t get the ‘:’ syntax right the first time, so I 
gave up on that 
[(_ (fn-name:id {arg t} ...) Tresult body ...)
 #'(begin
 (: fn-name (-> t ... Tresult))
 (define fn-name (memoize (lambda ({arg : t} ...) body ...]))


(define-memoized (fib {n Integer}) Integer
  (if (<= n 1)
  1
  (+ (fib (- n 1))
 (fib (- n 2)

(fib 10)



> On Sep 5, 2016, at 3:11 AM, Sourav Datta  wrote:
> 
> Another day, another typed racket question!
> 
> I was experimenting with memoize library in Racket and noticed that it does 
> not always work with typed racket functions (or, may be I was not 
> 'require'ing it properly). So I came up with this crude implementation below 
> and it seems to be working for one or more arguments:
> 
> #lang typed/racket
> 
> (: memoize (All (r a ...)
>(-> (-> a ... a r)
>  (-> a ... a r
> (define (memoize fn)
>  (let ([store : (HashTable Any r) (make-hash)])
>(define (memfn . [args : a ... a])
>  (hash-ref store args
>(lambda ()
>  (let ([result : r (apply fn args)])
>(hash-set! store args result)
>result
>memfn))
> 
> So the typical fibo function with this memoization function would look like:
> 
> (: fibo (-> Integer Integer))
> (define fibo (memoize (lambda ([n : Integer])
>(if (<= n 1)
>1
>(+ (fibo (- n 1))
>   (fibo (- n 2)))
> 
> However, what I wanted is to define a macro similar to define/memo like in 
> the Racket memoize package. A first approach like below did not work:
> 
> (define-syntax (define-memoized stx)
>  (syntax-parse stx
>[(_ (fn-name:id arg:id ...) body ...+)
> #'(define fn-name (memoize (lambda (arg ...) body ...)))]))
> 
> The error comes in (<= n 1) call where it is given Any but expecting Integer. 
> The problem is that the syntax splits the function definition in a lambda 
> expression and then passes to memoize function, whose result is then assigned 
> to the function name. The lambda expression without type annotation assumes 
> that the arguments are Any. 
> 
> So in this case, is there any way we could write a macro on top of the above 
> memoize that can identify the types of the underlying function and annotate 
> the lambda accordingly - or is there any other way this could be achieved?
> 
> Thanks!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scribble: unnumbered and unindexed sections

2016-09-05 Thread Shriram Krishnamurthi
Just as a note of warning to other readers. I like being able to use #:tag
for sections to get human-readable file/directory names. Unfortunately,
using the tag prefixes also affects these names. For instance, if you use
#:tag "foo", you get a file named "foo.html". But if you use #:tag-prefixes
"foo" as well, then you end up with "foofoo.html", which can look very
strange.

There's probably another flag to fix this too, but I haven't found it yet.
(-:

Shriram

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scribble: unnumbered and unindexed sections

2016-09-05 Thread Shriram Krishnamurthi
Thanks all for the help.

To summarize for the benefit of those who find this thread later:

A style of 'unnumbered does the trick. Thus

  @section[#:style 'unnumbered]{My Section}

will list it without giving it a number.

As for avoiding duplicate tags, this doesn't appear to be quite right:


> If you go the latter route, you'll also need to use `#:tag-prefix` in a
> cross-reference to a subsection (if you have any besides "Handin
> Instructions") in one of the N sections.
>

It appears that the actual keyword argument is #:tag-prefixes [note extra
"es"], and it takes a list of tags.

Thus, with only one prefix, a source document with

  @section[#:tag "uniq" #:tag-prefix "uniq"]{My Section}

can be referenced as

  (secref #:tag-prefixes (list "uniq") "uniq")

[But of course there's no reason for the tag and the tag-prefix to be the
same string.]

And of course you can combine these:

  @section[#:style 'unnumbered #:tag "uniq" #:tag-prefix "uniq"]{My Section}

Shriram

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] syntax-parse in typed racket

2016-09-05 Thread Sourav Datta
Another day, another typed racket question!

I was experimenting with memoize library in Racket and noticed that it does not 
always work with typed racket functions (or, may be I was not 'require'ing it 
properly). So I came up with this crude implementation below and it seems to be 
working for one or more arguments:

#lang typed/racket

(: memoize (All (r a ...)
(-> (-> a ... a r)
  (-> a ... a r
(define (memoize fn)
  (let ([store : (HashTable Any r) (make-hash)])
(define (memfn . [args : a ... a])
  (hash-ref store args
(lambda ()
  (let ([result : r (apply fn args)])
(hash-set! store args result)
result
memfn))

So the typical fibo function with this memoization function would look like:

(: fibo (-> Integer Integer))
(define fibo (memoize (lambda ([n : Integer])
(if (<= n 1)
1
(+ (fibo (- n 1))
   (fibo (- n 2)))

However, what I wanted is to define a macro similar to define/memo like in the 
Racket memoize package. A first approach like below did not work:

(define-syntax (define-memoized stx)
  (syntax-parse stx
[(_ (fn-name:id arg:id ...) body ...+)
 #'(define fn-name (memoize (lambda (arg ...) body ...)))]))

The error comes in (<= n 1) call where it is given Any but expecting Integer. 
The problem is that the syntax splits the function definition in a lambda 
expression and then passes to memoize function, whose result is then assigned 
to the function name. The lambda expression without type annotation assumes 
that the arguments are Any. 

So in this case, is there any way we could write a macro on top of the above 
memoize that can identify the types of the underlying function and annotate the 
lambda accordingly - or is there any other way this could be achieved?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.