Question

I'm working on a PL logic resolver, and I need to make sure the input either has no spaces, or evenly spaced. I think removing the spaces will be easier. So I'm writing a function that removes the spaces from an input.

So far I have:

;sample input
(define KB&!alpha
  '((Girl)
    (~ Boy)
    (~~Boy)
    ( ~(FirstGrade ^ ~ ~ Girl))
    (Boy / Child)))

(define formatted null)

;formatting function
(define (Format_Spaces KB&!alpha)
  (for/list ((item KB&!alpha))
    (cond 
      ((list? item)(Format_Spaces item))
      ((not (eq? item " "))(set! formatted (append formatted (list item))))
      ((eq? item " ")(Format_Spaces (cdr KB&!alpha)))
    )
  )
)

But it's clearly giving me the wrong output.

Not only are the spaces still there, the output is a weird combination of the input. Can anybody help me out on this?

I want to get something like this:

'((FirstGrade)
    (FirstGrade=>Child)
    (Child^Male=>Boy)
    (Kindergarten=>Child)
    (Child^Female=>Girl)
    (Female)))

Thanks for reading.

EDIT: I'm trying to make the input uniform in format. In the new sample input, (~ Boy) is parsed as 2 symbols, (~~Boy) as 1 symbol, and (~ ~ Girl) as 3. I think this will be difficult to parse. Especially with different variations of symbols/operators/spaces. (ie. is "Child^" to be parsed as "Child","^" or as "Child^" a whole symbol?)

Was it helpful?

Solution

RE-EDIT:

Based on the comments you've made below, it looks to me like you're actually going to be writing this algorithm in Racket.

In that case, I have a much simpler prescription for you: Don't Do Anything. In particular, your input doesn't currently contain any spaces at all. The spaces you see are being inserted as part of Racket's display mechanism, in much the same way that a database printer might print fields separated with commas or tabs.

Rather than worrying about the commas, focus on the resolution algorithm. What does it take, and what does it produce?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top