Sebastian Wells <sebastian@here.com.invalid> wrote or quoted: |..etc,
taking into account that Python "lists" are really |arrays, and there's
no real Lisp equivalent to tuples,
Well, you could say that, in LISP, the dotted pair
( 1 . ( 2 . NIL ))
represents the list (1 2) while
( 1 . 2 )
represent the tuple "1,2".
|but they're essentially arrays also.
|Lisp, there's no reader that will give you the original structure |from
its string representation without having to also evaluate it
In Python, the ast module can yield the structure of a module of
Python code (including list and tuple literals) without the need to
execute that code.
def postprocess( parse_result ):
if isinstance( parse_result, _ast.Module ):
return postprocess( parse_result.body[ 0 ] )
elif isinstance( parse_result, _ast.Expr ):
return postprocess( parse_result.value )
elif isinstance( parse_result, _ast.Tuple ):
return \
tuple( postprocess( element )for element in parse_result.elts )
elif isinstance( parse_result, _ast.Constant ):
return parse_result.value
The thing that makes Python tuples different
from Python lists is that tuples are
immutable. Lisp doesn't have a type that
is "a list (or array) but it's immutable."
It doesn't yield actual lists or tuples, so you can't use it the
way OP was suggesting, that is, the way you'd use the corresponding
Lisp feature.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 447 |
Nodes: | 16 (2 / 14) |
Uptime: | 24:20:34 |
Calls: | 9,235 |
Calls today: | 2 |
Files: | 13,496 |
Messages: | 6,063,716 |