473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Optional algol syntax style

I think, allowing to specify blocks with algol style (for-end, if-end,
etc) will allow to write easy php-like templates
and would attract new web developers to python (as php and ruby do).
It can be straight compilled into Python bytecode cause there is
one-to-one transformation.
So this:
# -*- syntax-style: algol -*-
class asd:
def __init__(self,a):
if a:
for i in xrange(100):
pass
else:
while false:
pass
else:
pass
end
end
else:
self.a=None
end
end
end
is equivalent for:
class asd:
def __init__(self,a):
if a:
for i in xrange(100):
pass
else:
while false:
pass
else:
pass
else:
self.a=None
but could be written as:

# -*- syntax-style: algol -*-
class asd: def __init__(self,a): if a: for i in xrange(100): pass; else:
while false: pass; else: pass; end; end; end; end;

which is easier to embed into http template (php and ruby shows it).

And, maybe, there can web syntax - equivalent for php and ruby template:
<%# -*- syntax: web -*-%>
<%# -*- command: print -*- %>
<%
def print_all(l):%>
<table><%
for k in l:%>
<tr><td>#{k.name}</td><td>#{k.surname}</td></tr>
<%end%>
</table>
<%end
# -*- command: yield -*-
def yield_all(l):%>
<table><%
for k in l:%>
<tr><td>#{k.name}</td><td>#{k.surname}</td></tr>
<%end%>
</table>
<%end
# -*- command: S.write -*-
def write_all(S,l):%>
<table><%
for k in l:%>
<tr><td>#{k.name}</td><td>#{k.surname}</td></tr>
<%end%>
</table>
<%end%>

will be translated as it were written:
def print_all(l):
print (r"<table>")
for k in l:
print (r"<tr><td>"+`k.name`+ r"</td><td>"+`k.surname`+ r"</td></tr>")
# or print (r"<tr><td>"+str(k.name)+ r"</td><td>"+str(k.surname)+
r"</td></tr>")
print (r"</table>")
def yield_all(l):
yield (r"<table>")
for k in l:
yield (r"<tr><td>"+`k.name`+ r"</td><td>"+`k.surname`+ r"</td></tr>")
yield (r"</table>")
def write_all(S.l):
S.write (r"<table>")
for k in l:
S.write (r"<tr><td>"+`k.name`+ r"</td><td>"+`k.surname`+
r"</td></tr>")
S.write (r"</table>")

I offer to include it into iterpretter, so we can leave another
compilation stage, as it exists with popular
template libraries, which compile their template files into bytecode (or
python source)

Sep 5 '05 #1
3 1569
Sokolov Yura wrote:
I think, allowing to specify blocks with algol style (for-end, if-end,
etc) will allow to write easy php-like templates
and would attract new web developers to python (as php and ruby do).
It can be straight compilled into Python bytecode cause there is
one-to-one transformation.
[snip details]


Standard answer to this kind of question:

You can already do that in Python. It's spelled #end.

/MiO
Sep 5 '05 #2
You didn't quite get the OP's intention, I guess.

The OP wanted Python to be a bit more freeform by adding "end" tags.
That might be an improvement for web scripting, but I haven't seen the
solutions of the existing frameworks and won't dare to compare.

Sep 5 '05 #3
"Christoph Rackwitz" <ch****************@gmail.com> writes:
You didn't quite get the OP's intention, I guess.

The OP wanted Python to be a bit more freeform by adding "end" tags.
That might be an improvement for web scripting, but I haven't seen the
solutions of the existing frameworks and won't dare to compare.


Existing frameworks (the one's I've looked at anyway) tend to replace
indents with end tags of some kind. Doing anything else tends to get
ugly unless the language you are templating for treats whitespace the
same way Python does.

I'd argue that you're better off using a real templating system than
trying to mangle Python into becoming a more acceptable templating
system. For templates, you tend to want to access multiple different
names spaces that are only vaguelly related to the Python contextual
name spaces. For example, you may want CGI (or whatever variables)
available directly in the template, rather than as
CGI["foobar"].value. However, you don't want them showing up in front
of your templat variables; you want to be able to say "add CGI
variables foo, bar and foobar to the current name space" in a short
manner.

Templating systems (well, the better ones, anyway) let you manipulate
those name spaces in ways you can't do in python. Cheeta and
ClearSilver come to mind as systems that will let you do this.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Sep 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rob Long | last post by:
Hey, I've just noticed a somewhat annoying feature with PHP5 type hinting. You cannot hint types on optional arguments like this: class MyClass { function someFunc(Type1 $arg1, Type2 $arg2...
0
by: lakshmi | last post by:
include the following lines of code: using System.Runtime.InteropServices; prefix the optional argument with This takes care if an optional parameter is not supplied by a VB script client....
1
by: Do | last post by:
Hi: What's the syntax for an optional parameter in my function? I've done so many ASP 3.0 Web Classes that I haven't experienced the "Optional" parameter. Eg. Public function adduser(ByVal...
3
by: guy | last post by:
found this oddity- copying a vb6 function with optional parameters and pasting it into a vb2003 class, for conversion purposes, it all works fine except that the collapsing "-" on the LHS goes...
8
by: Alan J. Flavell | last post by:
What I was trying to do: to offer a default stylesheet, plus another small stylesheet which can be applied additionally to the default one. Preferably, the optional stylesheet should be initially...
10
by: deko | last post by:
In VB, I could do this: MyFuncrion(this As String, that As Integer, Optional otherThing As Boolean) do stuff here End Function In C#, I can use "out" to return multiple values from a method,...
12
by: Nick Hounsome | last post by:
Can anyone tell me what the rational is for not supporting optional arguments. It is obviously a trivial thing to implement and, since C++ has them, I would not expect them to be omitted without...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
1
by: MisterWilliam | last post by:
I noticed that in PEP 3105, the PEP about turning print to print(), the syntax for print() is defined as follows: def print(*args, sep=' ', end='\n', file=None) Ignoring the fact that print is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.