Re: [racket-users] Emitting structured logs

2019-03-31 Thread Darren Newton
Ah yes, that worked great!

was able to generate

```
{"data":{"foo":["a"]},"timestamp":"2019-03-31T11:22:57", 
"level":"INFO","name":"log-name"}
```

using 

```
(log-message app-logger 'info "" (hasheq 'foo '("a"))) 
```

On Sunday, March 31, 2019 at 8:43:00 AM UTC-4, Matthew Flatt wrote:
>
> At Sun, 31 Mar 2019 05:13:45 -0700 (PDT), Darren Newton wrote: 
> > However, I would like to pass a jsexpr? to the logger [...] 
> > 
> > As far as I can tell, the log procs only accept strings. 
>
> The primitive `log-message` function accepts arbitrary data for the 
> logged message after the message string. That data is communicated to 
> each log receiver. 
>
> The `log-info`, etc., macros currently support only a message string, 
> but you can create your own macro if that's helpful. If you know that 
> some receiver will exist a `log-level?` test as built into the existing 
> macros isn't helpful, and you might just as well call `log-message` 
> directly. 
>
>

-- 
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] [ANN] Algebraic Racket

2019-03-31 Thread Eric Griffis
I am pleased to announce Algebraic Racket, an extension for algebraic
structures in untyped Racket.

https://github.com/dedbox/racket-algebraic

Algebraic structures provide the operational under-pinnings for algebraic
data types. What's missing is the static typing constraints.

The initial release provides a #lang algebraic/racket/base that extends
#lang racket/base with:

1. First class, lexically scoped, naturally ordered data constructors.

  > (data Maybe (Just Nothing))
  > (define maybe
  (function*
[(n _ Nothing) n]
[(_ f (Just x)) (f x)]))
  > (maybe #f values (Just 123))
  123
  > (maybe #f values Nothing)
  #f

2. A consistent destructuring syntax for functions and macros.

  > (define fib
  (function
[n #:if (< n 2) 1]
[n (+ (fib (- n 1))
  (fib (- n 2)))]))
  > (map fib (build-list 7 values))
  '(1 1 2 3 5 8 13)

  > (define-syntax m-fib
  (macro
[n:nat #:if (< (var n) 2) 1]
[n:nat (+ (m-fib #,(- (var n) 1))
  (m-fib #,(- (var n) 2)))]))
  > (list (m-fib 0) (m-fib 1) (m-fib 2)
  (m-fib 3) (m-fib 4) (m-fib 5) (m-fib 6))
  '(1 1 2 3 5 8 13)

The package is fully documented. The documentation includes the first of
three tutorials in a series on building interpreters with Algebraic
Racket.

Algebraic Racket is the first major milestone in a larger effort to
produce a complete language-oriented toolkit for integrating algebraic
structure into more sophisticated designs.

The project aims to:

  1. Implement and document the forms, functions, and syntax classes
 comprising Algebraic Racket for maximum potential reuse.

  2. Support the development of modular type systems and other
 language-facing components as libraries.

Pull requests of any size are welcome. For major changes, please start a
conversation on racket-users or open an issue to discuss what you would
like to change.

-- 
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] Emitting structured logs

2019-03-31 Thread Matthew Flatt
At Sun, 31 Mar 2019 05:13:45 -0700 (PDT), Darren Newton wrote:
> However, I would like to pass a jsexpr? to the logger [...]
> 
> As far as I can tell, the log procs only accept strings.

The primitive `log-message` function accepts arbitrary data for the
logged message after the message string. That data is communicated to
each log receiver.

The `log-info`, etc., macros currently support only a message string,
but you can create your own macro if that's helpful. If you know that
some receiver will exist a `log-level?` test as built into the existing
macros isn't helpful, and you might just as well call `log-message`
directly.

-- 
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: Example "RealWorld" web application

2019-03-31 Thread Darren Newton
This is a great idea. Curious if you plan to do the front-end in 
Racketscript?

On Wednesday, March 27, 2019 at 8:03:57 PM UTC-4, Philip McGrath wrote:
>
> The RealWorld  project defines a simple but 
> realistic client–server web application (a Medium-like blogging platform) 
> for different front- and back-end frameworks to implement as an extended 
> tutorial example. The API is standardized, so different front- and 
> back-ends can be used interchangeably. (The rationale was announced here 
> .)
>
> I think an example implementation in Racket would be a great way to get 
> some visibility for Racket in the web development community. I would see it 
> as complementary to Continue . 
> (Maybe part or all of it could even be a literate program?)
>
> I've made a stub repository at 
> https://github.com/liberalartist/racket-realworld-example-app in the hope 
> of doing some work on this in my spare time. If anyone is interested in 
> collaborating, please get in touch!
>
> -Philip
>

-- 
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] Emitting structured logs

2019-03-31 Thread Darren Newton
I'm currently working on an application that uses structured logs (JSON) 
instead of the traditional string formatted logs. 
I currently have a log message handler based on some work Greg Hendershott 
put together:

```
(define (handle-log-message receiver)
  (λ (out)
(match (sync receiver)
  [(vector event-level event-message event-value name)
   (displayln
(jsexpr->string
 (hasheq 'timestamp (date->string (current-date) #t)
 'level ((compose string-upcase symbol->string)
 event-level)
 'msg (regexp-replace #rx"(^[a-z]*): " event-message "")
 'name (symbol->string name)))
out)])))
```

When I setup a log-writer this works well with simple logs like

```
(log-app-info "START")
```

Which will emit a log entry such as:

```
{"msg":"START","level":"INFO","name":"log-name","timestamp":"2019-03-30T18:27:29"}
```

However, I would like to pass a jsexpr? to the logger, such as `(log-app-info 
(hasheq 'tags '("a" "b" "c")))`
to get a log entry such as:

```
{"msg": {"tags": ["a", "b", 
"c"]},"level":"INFO","name":"log-name","timestamp":"2019-03-30T18:27:29"}
```

This is pretty common when working with AWS and other log services and is 
something I do at work with a Python lib 
(https://www.structlog.org/en/stable/)

As far as I can tell, the log procs only accept strings. Would l need to 
convert my log message into a JSON string, then in the log handler 
convert it back into a jsexpr? and then back into a string? If that is the 
case is it possible to wrap the the `(log--)` procs
in a macro to automate this?

Thanks in advance for any tips

-- 
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] Emacs scribble-mode

2019-03-31 Thread Alex Harsanyi
I started writing Scribble documentation more often lately and Emacs has no 
good support for editing such documents.  For me the main feature that I 
would like is indentation, like it is done in other programming modes.   I 
found a `racket-mode` on GitHub, but it only supports some basic syntax 
highlighting and nothing else.

In any case, I started implementing a scribble mode with aims of supporting 
indentation, document navigation and some more advanced syntax 
highlighting.  At this point it supports indentation and some basic code 
navigation (beginning/end of defun), but I indent to improve it as I use it 
for Scribble editing (unless there is a better package that I don't know 
about?)

If you are also interested in Scribble support for Emacs, you can check out 
the source here:

https://github.com/alex-hhh/racket-mode/blob/master/scribble-mode.el

Best Regards,
Alex.


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