[Python-Dev] slice notation and RDF

Damien Morton Damien.Morton@acm.org
Thu, 2 May 2002 02:04:08 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0072_01C1F17D.A5331940
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I was reading TBLs presentation of webizing Python, and specifically his
ideas about incorporating RDF into the syntax of Python.
 
The recent thread on slice notation, and some of my experiences playing
around implementing syntax for TBLs RDF-in-Python proposal got me
thinking.
 
Could the notation   a:b:c:d:... be generalised, with slices becoming a
kind of tuple. For backwards compatability, the first three elements of
the tuple could be accessed using the start, stop, step attributes.
 
Could the dictionary notation be related to slice notation, such that a
dictionary is defined as being an object initialised by a list of
slices.
 
{ 1:2, 3:4 } <--> dict([slice(1,2), slice(3,4)])
 
For RDF notation, you could then happily write:
 
{1:2:3, 4:5:6, 7:8:9} --> dict([slice(1,2,3), slice(4,5,6),
slice(7,8,9)])
 
For sets, you would write:
 
{1, 2, 3} -> dict([slice(1), slice(2), slice(3)]}
 
A slice on its own would be writen:
 
(1:2:3)  -> slice(1,2,3)
 
A 1-element slice might be written similarily to a 1-element tuple:
(1:) -> slice(1)

------=_NextPart_000_0072_01C1F17D.A5331940
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Message</TITLE>

<META content=3D"MSHTML 5.50.4807.2300" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>I was =
reading TBLs=20
presentation of webizing Python, and specifically his ideas about =
incorporating=20
RDF into the syntax of Python.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>The =
recent thread on=20
slice notation, and some of my experiences playing around implementing =
syntax=20
for TBLs RDF-in-Python proposal got me thinking.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>Could =
the=20
notation&nbsp;&nbsp; a:b:c:d:... be generalised, with slices becoming a =
kind of=20
tuple. For backwards compatability, the first three elements of the =
tuple could=20
be accessed using the start, stop, step attributes.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>Could =
the dictionary=20
notation be related to slice notation, such that a dictionary is defined =
as=20
being an object initialised by a&nbsp;list of =
slices.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>{ 1:2, =
3:4 }=20
&lt;--&gt; dict([slice(1,2), slice(3,4)])</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>For =
RDF notation,=20
you could then happily write:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D795433805-02052002>{1:2:3, 4:5:6,=20
7:8:9} --&gt; dict([slice(1,2,3), slice(4,5,6),=20
slice(7,8,9)])</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>For =
sets, you would=20
write:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>{1, 2, =
3} -&gt;=20
dict([slice(1), slice(2), slice(3)]}</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>A =
slice on its own=20
would be writen:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D795433805-02052002>(1:2:3)&nbsp; -&gt;=20
slice(1,2,3)</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D795433805-02052002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>A =
1-element slice=20
might be written similarily to a 1-element tuple:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D795433805-02052002>(1:) =
-&gt;=20
slice(1)</SPAN></FONT></DIV></BODY></HTML>

------=_NextPart_000_0072_01C1F17D.A5331940--