[racket] Please help with syntax

From: Jos Koot (jos.koot at gmail.com)
Date: Sat Jun 28 03:41:38 EDT 2014

#lang racket
 
(define-syntax (set!-values* stx)
 (syntax-case stx ()
  ((_ (var ...) values-expr)
   (with-syntax (((local-var ...) (generate-temporaries #'(var ...))))
  #'(let-values (((local-var ...) values-expr))
     (set!* var local-var) ...)))))
 
(define-syntax (set!* stx)
 (syntax-case stx ()
  ((_ var val) (free-identifier=? #'var #'_) #'foid)
  ((_ var val) #'(set! var val))))
 
(define foid (void))
 
(define-values (a b c) (values 1 2 3))
(set!-values* (_ _ c) (values 4 5 6))
(list a b c)

Jos


________________________________

	From: users [mailto:users-bounces at racket-lang.org] On Behalf Of
Roman Klochkov
	Sent: sábado, 28 de junio de 2014 8:43
	To: Racket Users List
	Subject: [racket] Please help with syntax
	
	
	I need to define syntax set!-values*, that will ignore _ in value
place.
	
	Such as
	(define a #f)
	(set!-values* (_ _ a) (values 1 2 3)) ; should set a to 3.
	
	But I have two problems:
	1. _ don't want to pattern match in syntax case. If I make it
literal, I can't match "anything else".
	2. How to omit extra values. It seems that in any case I have to
assign them to something...
	
	Can you help me? I hope, that my problem in fact not hard, but I
have not enough experience to solve it.
	
	-- 
	Roman Klochkov 




Posted on the users mailing list.