How do I convert a list written on a text field from string to list?

I'm not an English native, so if there are any mistakes, please correct me. I have written a program that take an arithmetic expression and reduce it. It takes a list and return a list like this one: '((a + 2) * b). The user can only use addition and multiplication.

I'm trying to create a GUI which will take the list, reduce it and return the result. But the text field only returns a string value. I want to convert the sting value in a list like the precedent example. If the user write (a + (b * 1)), how do I convert it in a list (a + (b * 1))?

Here is what I have done.

(define (convert string)
  (map string->symbol          ; convert each substring into a symbol
       (string-split string))) ; split the string by its spaces

; Crée une fenêtre "Simplifier"
(define frame (new frame% [label "Simplifier"]))

; Crée un conteneur "panel"
(define panel (new vertical-panel% [parent frame]))

; Crée un message dans le conteneur "panel)
(define msg (new message%
                 [parent panel]
                 [label "Donnez une expression à simplifier.
N'oubliez pas les parenthèses!"]))

; Crée un champ de texte
(define text-field (new text-field%
                        (label "Expression : ")
                        (parent panel)))

; Crée un message qui affichera le résultat
(define message (new message%
                     (parent panel)
                     (auto-resize #t)
                     (label " ")))

; Faire le bouton "Validez"
(new button% [parent panel]
             [label "Validez"]
             ; Procédure Callback pour un clique sur le bouton "Validez":
             [callback (lambda (button event)
                         (define text (simplifier (convert (send text-field get-value))))
                         (send message set-label (slist->string text)))])

; Affiche la fenêtre
(send frame show #t)

Here is the result of convert:

> (convert "(a + b)")
'(|(a| + |b)|)

Here is a modification of that I have done.

(new button% [parent panel]
             [label "Validez"]
             ; Procédure Callback pour un clique sur le bouton "Validez":
             [callback (lambda (button event)
                         (define text (simplifier (read (open-input-string (send text-field get-value)))))
                         (send message set-label (slist->string text)))])

It works when I test in the interpreter.

> (read (open-input-string "(a + (b + c))")) :  '(a + (b + c))
'(a + (b + c))

But on the window, I write the same thing, and it returns this :
symbol→string: contract violation expected: symbol? Given: '(b + c)

Can I have a suggestion? Thanks in advance.

I was going to steer you to the design recipe... and at some point soon I probably will... but in this case, you're trying to duplicate functionality that is 100% already in existence:

#lang racket

(require rackunit)

(define (convert str)
  (read (open-input-string "(a + b)")))

(check-equal? (convert "(a + b)") '(a + b))

It's perhaps worth noting that this will only read the first s-expression from the string, so for instance (convert "(a + b)(a + b)") will only return '(a + b); if that's a problem, you'll have to build a loop to read repeatedly.

It works when I test in the interpreter.

> (read (open-input-string "(a + (b + c))"))
'(a + (b + c))

But on the window, I write the same thing, and it returns this on the interpreter :
symbol→string: contract violation expected: symbol? Given: '(b + c)

Can I have a suggestion? Thanks in advance.

I know why it doesn't work. Because this function only work with simple list.

(define (slist->string slst)
  (string-join (map symbol->string slst) " "))

I will try to modify it and see if it works.
I will update tomorrow.

Hi, sorry I didn't keep my promise to update.
Here how I made it work.

; Convert a list in a list of string
(define list->slist (lambda (l)
                      (cond
                        ((null? l)       '())
                        ((list? (car l)) (cons (list->slist (car l)) (list->slist (cdr l))))
                        ((Cte? (car l))  (cons (number->string (car l)) (list->slist (cdr l))))
                        (#t              (cons (symbol->string (car l)) (list->slist (cdr l))))
                        )))

; Convert a list of string in string
(define convert (lambda (slst)
                  (cond
                    ((null? slst)       "")
                    ((list? (car slst)) (string-append "(" (convert (car slst)) " " (convert (cdr slst)) ")"))
                    (#t                 (string-append (car slst) " " (convert (cdr slst))))
                    )))

It works for me. I can't see any simpler way.
Thanks for the help.