Pattern Matching

97 views
Skip to first unread message

Beatriz Moreira

unread,
Sep 28, 2020, 10:50:47 AM9/28/20
to Racket Users
Hello,
I would like to know how do I match multiple variables to a regular expression.
My idea is to match every f variables (f...) to an f in ((contract C ((T x) ...) ((T f)) ...) ... ).
I am trying to implement a core language for smart contracts in Racket, but I need to have as pre condition in my reduction rules that the f is a function in one of the contracts.
Thank you! :) 


George Neuner

unread,
Sep 28, 2020, 3:31:11 PM9/28/20
to Beatriz Moreira, racket users

On 9/28/2020 10:50 AM, Beatriz Moreira wrote:
Hello,
I would like to know how do I match multiple variables to a regular expression.
My idea is to match every f variables (f...) to an f in ((contract C ((T x) ...) ((T f)) ...) ... ).
I am trying to implement a core language for smart contracts in Racket, but I need to have as pre condition in my reduction rules that the f is a function in one of the contracts.
Thank you! :)

'regexp-match*' outputs a list of matched strings, and match has an apply clause: '(app expr pats ...)' which evaluates expr and tries to match the output.  My first thought would be to try something like:

  match ( inp )
    :
    ((app (regexp-match* pattern inp) match1 match2 ... )
       ... )
    :

Caveat ... I've never tried to do this.  If match doesn't like this approach (or something close to it), then I would separately perform the regexp-match* and the pattern match on its output list.

Hope this helps,
George

https://docs.racket-lang.org/reference/regexp.html
https://docs.racket-lang.org/reference/match.html

Wesley Bitomski

unread,
Sep 29, 2020, 12:20:58 PM9/29/20
to Racket Users
Hello Beatriz,

Is this something like contracts with parameters? That sounds neat, actually.

Anyway, this seems more like syntax analysis rather than string matching, but I'm not entirely certain as to what your approach is. I can't access the file you linked.

If this _is_ syntax analysis, then maybe a macro using `syntax-case` or `syntax-parse` would serve you better? Again, I'm not exactly sure what your approach is, and I'm sorry for that.

Beatriz Moreira

unread,
Oct 6, 2020, 10:37:10 AM10/6/20
to Racket Users
Hello,
I don't think this is what im looking for, but thank you very much :D 

Beatriz Moreira

unread,
Oct 6, 2020, 10:41:00 AM10/6/20
to Racket Users
Hello,

Yes, my idea is to check the type of the parameters. I still have to add the types to my code, but I was trying to see if I could do it without them (just pattern matching), as the functions of type f are in the declaration of the contract.

Thank you for your answer :D

George Neuner

unread,
Oct 6, 2020, 12:55:22 PM10/6/20
to Beatriz Moreira, racket users

On 10/6/2020 10:41 AM, Beatriz Moreira wrote:
Hello,

Yes, my idea is to check the type of the parameters. I still have to add the types to my code, but I was trying to see if I could do it without them (just pattern matching), as the functions of type f are in the declaration of the contract.

Thank you for your answer :D

I thought you were working with match in Racket ... Redex is its own language, and I haven't done anything with it.

Sorry, I can't help.
George


Reply all
Reply to author
Forward
0 new messages