Re: [racket-users] Beginners question: implementing existing generics for existing structs

2017-02-02 Thread Ronie Uliana
Thank you, Jon and andmkent!

Jon, I understand the reason. However, I guess it's possible to fix that kind 
of problem using precedence the same way some languages do with traits and 
mixins.

:)

Anyway, thank you again!

-- 
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] Beginners question: implementing existing generics for existing structs

2017-01-31 Thread Ronie Uliana
Let's assume I have a struct that is not mine (like ddict 
[https://pkgn.racket-lang.org/package/ddict], or some of pfds 
[https://pkgn.racket-lang.org/package/pfds]). I'd like to implement generics 
for them that also are not mine :p (like data/collection from Alexis King).

1 - Is it possible?
2 - How do I do that?

I searched through generics documentation, but I think I completely missed that 
part =/

[]s an thx!
Ronie

-- 
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] Re: What is the Racket equivalent to 'return' for early exit?

2016-11-22 Thread Ronie Uliana
Em segunda-feira, 21 de novembro de 2016 16:08:40 UTC-2, Leif Andersen  
escreveu:
> Honestly, I personally like to use let/ec for this. I know it's still using 
> continuations, but it is much more lightweight, both syntactically and in 
> terms of run-time costs.
> 
> (define (do-something)
> 
>   (let/ec return
>     (unless (some-condition)
>       (return NO))
> 
>     (do-the-thing)))
> 
> Although honestly, with this pattern, I find that errors work better here, as 
> they return early, and you can decide how they get handled with a 
> with-handlers.
> 
> (define (do-something)
>   (unless (some-condition)
>     (error "NO"))
>   (do-the-thing))
> 
> (with-handlers ([exn:fail? (lambda (e) (displayln "I returned early"))])
>   (do-something))
> 
> But that is specifically because I prefer the workflow of catching errors, 
> rather than always having to manually check the output of the function 
> (I'm looking at you C...)
> 
> Hope that helps.
> 
> 
> 
> 
> 
> 
> 
> ~Leif Andersen
> 
> 
> On Mon, Nov 21, 2016 at 12:41 PM, David Storrs  wrote:
> 
> 
> Edit:  I know I could also use call/cc and invoke the continuation to escape, 
> but that still adds another layer of indentation for something that in the 
> normal case won't be called.
> 
> It's not a big deal, but I was wondering about it.
> 
> 
> 
> 
> 
> On Mon, Nov 21, 2016 at 9:37 AM, David Storrs  wrote:
> 
> 
> 
> 
> In Perl I would often write:
> 
> sub do_something {
>     return unless ( some necessary condition is met );
> 
>     ... do the thing ...
> 
> }
> 
> In Racket I could wrap the rest of the procedure in an (if), but that adds an 
> unnecessary level of indentation and feels clunky.  Is there a clean solution?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 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...@googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

Just notice I replied the digest email instead of post a response. :p

So, let me try again and sorry for the mess...

I made this macro for exactly for the same reason (it's basically Leif's 
answer) :)

https://gist.github.com/ruliana/80d7bb46225a22a3682711ca8bd11a1d

@JohnClements, I guess you have a point :) but I think David is mostly talking 
about what we call "Guard Clauses" 
(http://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html), 
good or bad, they are a tool for simplifying code. But I agree, don't overdo it 
^_^

Macro copied below for convenience (btw, sorry for the code, Racket is not my 
main programming language... yet)


#lang racket
(require racket/stxparam)

(provide return
 define/guard)

(define-syntax-parameter return
(λ (stx)
  (raise-syntax-error (syntax-e stx) "can only used inside 
\"define/guard\"")))

(define-syntax-rule (define/guard (name args ...) body0 body ...)
(define (name args ...)
  (let/cc ret
(syntax-parameterize ([return (make-rename-transformer #'ret)])
  body0
  body ...

(define/guard (test2 a b)
  (when (> a b) (return 456))
  (displayln "hehehe")
  123)

-- 
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] Digest for racket-users@googlegroups.com - 10 updates in 1 topic

2016-11-22 Thread Ronie Uliana
I made this macro for exactly for the same reason :)

https://gist.github.com/ruliana/80d7bb46225a22a3682711ca8bd11a1d

@JohnClements, I guess you have a point :) but I think David is mostly
talking about what we call "Guard Clauses" (
http://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html),
good or bad, they are a tool for simplifying code. But I agree, don't
overdo it ^_^

Macro copied below for convenience (btw, sorry for the code, Racket is not
my main programming language... yet)


#lang racket (require racket/stxparam)
(provide return
define/guard)
(define-syntax-parameter return
(λ (stx)
(raise-syntax-error (syntax-e stx) "can only used inside \"define/guard\""
)))
(define-syntax-rule (define/guard (name args ...) body0 body ...)
(define (name args ...)
(let/cc ret
(syntax-parameterize ([return (make-rename-transformer #'ret)])
body0
body ...
(define/guard (test2 a b)
(when (> a b) (return 456))
(displayln "hehehe")
123)

Em ter, 22 de nov de 2016 às 05:24, 
escreveu:

> racket-users@googlegroups.com
> 
>  Google
> Groups
> 
> 
> Topic digest
> View all topics
> 
>
>- What is the Racket equivalent to 'return' for early exit?
><#m_-7182901911078251811_group_thread_0> - 10 Updates
>
> What is the Racket equivalent to 'return' for early exit?
> 
> David Storrs : Nov 21 09:37AM -0800
>
> In Perl I would often write:
>
> sub do_something {
> return unless ( some necessary condition is met );
> ... do the thing ...
> }
>
> In Racket I could wrap the rest of the procedure in an (if), but that adds
> an unnecessary level of indentation and feels clunky. Is there a clean
> solution?
> David Storrs : Nov 21 09:41AM -0800
>
> Edit: I know I could also use call/cc and invoke the continuation to
> escape, but that still adds another layer of indentation for something that
> in the normal case won't be called.
>
> It's not a big deal, but I was wondering about it.
>
> On Mon, Nov 21, 2016 at 9:37 AM, David Storrs 
> wrote:
>
> George Neuner : Nov 21 01:04PM -0500
>
> On 11/21/2016 12:41 PM, David Storrs wrote:
>
> > In Racket I could wrap the rest of the procedure in an (if), but
> > that adds an unnecessary level of indentation and feels clunky.
> > Is there a clean solution?
>
> In Racket, IF requires both alternatives be specified. What's wrong
> with WHEN or UNLESS?
>
> (define (do-something)
> (unless (some necessary condition is met)
> ... do the thing(s) ...)
> )
>
> George
> Leif Andersen : Nov 21 01:07PM -0500
>
> Honestly, I personally like to use let/ec for this. I know it's still using
> continuations, but it is much more lightweight, both syntactically and in
> terms of run-time costs.
>
> (define (do-something)
> (let/ec return
> (unless (some-condition)
> (return NO))
>
> (do-the-thing)))
>
> Although honestly, with this pattern, I find that errors work better here,
> as they return early, and you can decide how they get handled with a
> with-handlers.
>
> (define (do-something)
> (unless (some-condition)
> (error "NO"))
> (do-the-thing))
>
> (with-handlers ([exn:fail? (lambda (e) (displayln "I returned early"))])
> (do-something))
>
> But that is specifically because I prefer the workflow of catching errors,
> rather than always having to manually check the output of the function
> (I'm looking at you C...)
>
> Hope that helps.
>
>
> ~Leif Andersen
>
> On Mon, Nov 21, 2016 at 12:41 PM, David Storrs 
> wrote:
>
> "John Clements" : Nov 21 01:30PM -0500
>
> > ... do the thing ...
> > }
>
> > In Racket I could wrap the rest of the procedure in an (if), but that
> adds an unnecessary level of indentation and feels clunky. Is there a clean
> solution?
>
> Playing the role of irritating ideologue, it’s … me!
>
> Yes, there’s let/ec, but my (limited) experience in industry suggests that
> reading functions that use ‘return’ liberally can be massively more
> difficult than one that uses ‘if’ or a related form. I would argue that the
> call/ec doesn’t actually make the code less clunky, it just hides the
> clunkiness, and makes the code harder to read, to boot. In the absence of
> return, you can generally easily deduce when control flow reaches a
> particular point (“we only get here if x is > 0 and the string is empty”).
> In the presence of return, this becomes “we only get here if x is > 0 and
> the string is empty and one of these 19 incomprehensible clauses didn’t
> trigger a return.”
>
> I do think that call/ec makes sense in some circumstances; for instance,
> if you want to bail out of a deeply nested call, and the int

[racket-users] A Racket talk in Rubyconf Brazil

2016-09-25 Thread Ronie Uliana
Hi, there!

I gave a talk about Racket in Rubyconf Brazil yesterday (saturday 24).

Here  are the slides
translated to English and here
 the original in Portuguese
:)

Not sure I gave the right importance to the right points, but people liked
it a lot.

Thank you all for the amazing job in the Racket!

[]s
Ronie

-- 
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: Order of argument conventions, or ... conventions of argument ordering

2016-04-22 Thread Ronie Uliana
I like a lot this advice from Haskell:

"... in Haskell it is not possible to alter objects, but there are many 
functions which return a somehow altered input object. This object should be 
the last parameter because then you can compose a sequence of operations on 
this object" (https://wiki.haskell.org/Parameter_order)

That makes threading macros (~>>) easier to apply, and also to remember the 
argument order. :)

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


Re: [racket-users] Is it possible to implement generics to an already defined struct?

2016-03-06 Thread Ronie Uliana
Thank you, Andrew! :)

-- 
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] Is it possible to implement generics to an already defined struct?

2016-03-05 Thread Ronie Uliana
Sorry for the beginner question :(

I'm learning Racket and it is an amazing language. Documentation is great, but 
I couldn't find this.

Let's say I have a struct defined somewhere I have no control:

(struct blah (x y))

Now, in my module, I have this generics:

(define-generics my-thing
  (level my-thing))

Is it possible to make "blah" to implement "my-thing"? So I can use it like:

(level (blah 1 2))

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