简体   繁体   English

从球拍列表中删除空格

[英]Remove Spaces From List of Lists in Racket

I'm working on a PL logic resolver, and I need to make sure the input either has no spaces, or evenly spaced. 我正在开发PL逻辑解析器,并且需要确保输入没有空格或间隔均匀。 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. 在新的示例输入中,将(〜Boy)解析为2个符号,(~~ Boy)解析为1个符号,将(〜〜Girl)解析为3个符号。我认为这将很难解析。 Especially with different variations of symbols/operators/spaces. 尤其是符号/运算符/空格的不同变体。 (ie. is "Child^" to be parsed as "Child","^" or as "Child^" a whole symbol?) (即,将“ Child ^”解析为整个符号是“ Child”,“ ^”还是“ Child ^”?)

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. 根据您在下面的评论,在我看来,您实际上将要在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. 您所看到的空格是作为Racket的显示机制的一部分插入的,与数据库打印机可以打印用逗号或制表符分隔的字段的方式几乎相同。

Rather than worrying about the commas, focus on the resolution algorithm. 不必担心逗号,而是着眼于分辨率算法。 What does it take, and what does it produce? 它需要什么,它产生什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM