Renaming identifiers & debugging

L

Luca

Hello, i am trying to develop an application to teach programming to
young kids in a similar way as Logo did in the past. I would like to use
an embedded Python as underlying language but this raises a problem.

The target of my app are very young kids that might be unfamiliar with
english, so i am wondering if there is a way to rename/redefine
identifiers and messages in the language of the kid.

In UCB-Logo this is very easy with the command
COPYDEF "newidentifier "oldidentifier
so all you have to do is setup a startup script to redefine all the
identifiers to the language of the user.

Is there anything similar for python? Since python would be embedded it
would not be a problem for me to do it through some API.


Also, i would need a way to debug the program, so set up breakpoints,
execute line by line, inspect variables, is there any API for this in
embedded python?

Thank you,
Luca
 
S

Steven D'Aprano

Hello, i am trying to develop an application to teach programming to
young kids in a similar way as Logo did in the past. I would like to use
an embedded Python as underlying language but this raises a problem.

The target of my app are very young kids that might be unfamiliar with
english, so i am wondering if there is a way to rename/redefine
identifiers and messages in the language of the kid.
5

However, you can't rename statements such as for, while, if and similar,
nor can you rename error messages. There might be an internationalised
version of Python in the language the children speak. Have you tried
googling?

Also, i would need a way to debug the program, so set up breakpoints,
execute line by line, inspect variables, is there any API for this in
embedded python?

Have you tried the Python debugger?

import pdb
 
L

Luca

Steven said:
However, you can't rename statements such as for, while, if and similar,
nor can you rename error messages. There might be an internationalised
version of Python in the language the children speak. Have you tried
googling?

Yeah, this is what i am talking about. It seems that keywords (if,
while, for, etc) cannot be renamed at all. Not easily at least without
recompiling Python from source. Same thing with error messages.

What i need is not an internationalized version of python in a specific
language... but a simple way to let the teacher do it by
himself/herself. Since python will be embedded in my application i could
also load this via a text-file or XML file... but it seems that no API
has been made available to solve this problem.

Logo is the only language i know that lets the user do this in a very
simple way, that's why i brought it as example of what i need. In Logo
every identifier can be changed with a simple startup file and every
error message can be personalized by editing a text file. This allows
any user/parent/teacher to personalize the language for their kids. What
i need is an API that lets my application do something similar to the
python library. Unfortunately it seems that there is no easy way to do it.
Have you tried the Python debugger?

import pdb


Didn't know it, thank you. Now i need to understand if this PDB module
can be used from the application that is embedding pythong (so that i
can build a simple IDE to set breakpoints, show the current
execution-line, skip it, etc.

Thanx,
Luca
 
C

Chris Rebert

Hello, i am trying to develop an application to teach programming to young
kids in a similar way as Logo did in the past. I would like to use an
embedded Python as underlying language but this raises a problem.

The target of my app are very young kids that might be unfamiliar with
english, so i am wondering if there is a way to rename/redefine identifiers
and messages in the language of the kid.

In UCB-Logo this is very easy with the command
 COPYDEF "newidentifier "oldidentifier
so all you have to do is setup a startup script to redefine all the
identifiers to the language of the user.

Is there anything similar for python? Since python would be embedded it
would not be a problem for me to do it through some API.

It can certainly be done (c.f. ChinesePython -
http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html),
but I know of no framework that simplifies the task. Essentially, you
just have to manually modify Python's parser by swapping out the
english for the other language (and if you want to mess with the basic
types' names, their name definitions somewhere else too). There also
might be encoding issues to deal with.

Cheers,
Chris
 
L

Luca

Chris said:
It can certainly be done (c.f. ChinesePython -
http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html),
but I know of no framework that simplifies the task. Essentially, you
just have to manually modify Python's parser by swapping out the
english for the other language (and if you want to mess with the basic
types' names, their name definitions somewhere else too). There also
might be encoding issues to deal with.

Cheers,
Chris

Yes, i am playing with Python source code, i have changed some keywords
but the compile-process fails when it tries to compile some of python
libraries which, of course, use english keywords... so i guess this is
not a very clean/viable solution (without having to rewrite several
parts of the libraries). A better solution could be to "duplicate"
keywords adding a translated version but leaving the original version in
place so that every module keeps working. In few words, if i was going
to translate the keyword "if" in, say, italian "se", then i would have
both "if" and also "se" working at the same time, in the same manner.
I think that the best way to do this is to insert a "filter" somewhere
that converts every "se" keyword into a "if" keyword so that python
doesn't even see the change.

What i would like to do is add a new keyword (lets call it "copydef"
like in UCBLogo or whatever) that does this work at runtime by keeping a
substitution table in RAM. If i could manage to add this new keyword to
python then it would be easy to write a startup script that translates
the keywords once python is "up and running" and without breaking
existing python programs/libraries (unless the new keyword conflicts
with functions defined inside these programs/libraries).

Thanx,
Luca
 
M

MRAB

Luca said:
Yes, i am playing with Python source code, i have changed some keywords
but the compile-process fails when it tries to compile some of python
libraries which, of course, use english keywords... so i guess this is
not a very clean/viable solution (without having to rewrite several
parts of the libraries). A better solution could be to "duplicate"
keywords adding a translated version but leaving the original version in
place so that every module keeps working. In few words, if i was going
to translate the keyword "if" in, say, italian "se", then i would have
both "if" and also "se" working at the same time, in the same manner.
I think that the best way to do this is to insert a "filter" somewhere
that converts every "se" keyword into a "if" keyword so that python
doesn't even see the change.

What i would like to do is add a new keyword (lets call it "copydef"
like in UCBLogo or whatever) that does this work at runtime by keeping a
substitution table in RAM. If i could manage to add this new keyword to
python then it would be easy to write a startup script that translates
the keywords once python is "up and running" and without breaking
existing python programs/libraries (unless the new keyword conflicts
with functions defined inside these programs/libraries).
Perhaps you could use a different extension, eg ".pyn", so existing
".py" files are handled as-is but ".pyn" files are read through a
translator.
 
D

Diez B. Roggisch

Am 25.02.10 20:27, schrieb Luca:
Yes, i am playing with Python source code, i have changed some keywords
but the compile-process fails when it tries to compile some of python
libraries which, of course, use english keywords... so i guess this is
not a very clean/viable solution (without having to rewrite several
parts of the libraries). A better solution could be to "duplicate"
keywords adding a translated version but leaving the original version in
place so that every module keeps working. In few words, if i was going
to translate the keyword "if" in, say, italian "se", then i would have
both "if" and also "se" working at the same time, in the same manner.
I think that the best way to do this is to insert a "filter" somewhere
that converts every "se" keyword into a "if" keyword so that python
doesn't even see the change.

What i would like to do is add a new keyword (lets call it "copydef"
like in UCBLogo or whatever) that does this work at runtime by keeping a
substitution table in RAM. If i could manage to add this new keyword to
python then it would be easy to write a startup script that translates
the keywords once python is "up and running" and without breaking
existing python programs/libraries (unless the new keyword conflicts
with functions defined inside these programs/libraries).

You could use import-hooks for importing your code. There was a
python-magazine article a while ago that showed how to use that + a
parser to import seamlessly a DSL.

Using pyparsing to write a python-grammar on the fly that simply
exchanges the keywords before passing it to the interpreter is also easy.

But to be honest: I doubt it's worth the effort. Really. Teaching people
how to code, but in something that is *not* the "real" language is of
little, if any, benefit.

And also I don't think that your concerns are valid in general. Keywords
are like brandnames or other things - the stand for a concept, and
people immediatly accept them when they want them.

Much, much, much more important would - if anything - be a
standard-library, or a wrapper for that, e.g. for turtle-graphics, that
was written in terms of your desired language.

Diez
 
L

Luca

Diez said:
You could use import-hooks for importing your code. There was a
python-magazine article a while ago that showed how to use that + a
parser to import seamlessly a DSL.

I will look into this, right now i don't know what import-hooks are nor
if i can use them from embedded python.
Using pyparsing to write a python-grammar on the fly that simply
exchanges the keywords before passing it to the interpreter is also easy.

This could be an easy solution yes... unfortunately this makes other
problems arise... for instance... if i have an IDE that shows the
translated language and i want to debug it step by step... would it be
easy for me to map the english version (the one that python sees) with
the translated version? I still have to look at this and how to run the
debugger from the application that is "hosting" python so for now the
answer is "i don't know".

Right now, by simply changing the file Python-3.1.1/Grammar/Grammar i
could obtain this (with "if" translated in "se"):

Python 3.1.1 (r311:74480, Feb 25 2010, 22:44:50)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information..... stampa("Ciao")
....
Ciao
Which seems to work, but requires to manually change the source code and
it is way too complex for someone that has zero knowledge about the
internals of python (like myself). Besides... it is a very ugly hack IMO.
But to be honest: I doubt it's worth the effort. Really. Teaching people
how to code, but in something that is *not* the "real" language is of
little, if any, benefit.

And also I don't think that your concerns are valid in general. Keywords
are like brandnames or other things - the stand for a concept, and
people immediatly accept them when they want them.

Maybe you are right, but being italian myself i can remember when i was
a middle schooler (no computer before that) and the hours spent on my
MSX figuring out how the thing worked. I learned all the commands as
"brandnames" without really understanding them. I had _no_ idea that
"if" meant... if, or that "print" meant to print. I had zero knowledge
of english and for this reason most of these commands were meaningless
to me, i didn't even suspect they had a meaning in an existing language,
i just thought that was the way computers talked. When several years
later, in High School, i learned English it was a real surprise for me
to find out that the commands i had learned by heart as "magical words"
actually had a precise meaning in "human language" and i think this
would have helped me to figure out several things that instead took
hours or days to understand.
Now kids have internet, they study english from the kindergarten, they
have a huge quantity of manuals and books freely available, so maybe you
are right and i am just over-worrying. But still, i think it would be
nice to use a language familiar to the kid (especially very young ones),
it would make the learning process faster (no need to learn new words)
and it would make the computer feel almost like a virtual "friend".
Much, much, much more important would - if anything - be a
standard-library, or a wrapper for that, e.g. for turtle-graphics, that
was written in terms of your desired language.

I already made some tests with turtle-graphics and it seems to work. My
next problem was to translate the language.

http://img192.imageshack.us/img192/3093/zzz5.png

[Btw... i took too much time to write this post so the ladybug fell
asleep...]

Thanx,
Luca
 
N

News123

Hi Luca,
Hello, i am trying to develop an application to teach programming to
young kids in a similar way as Logo did in the past. I would like to use
an embedded Python as underlying language but this raises a problem.

The target of my app are very young kids that might be unfamiliar with
english, so i am wondering if there is a way to rename/redefine
identifiers and messages in the language of the kid.

In UCB-Logo this is very easy with the command
COPYDEF "newidentifier "oldidentifier
so all you have to do is setup a startup script to redefine all the
identifiers to the language of the user.

Is there anything similar for python? Since python would be embedded it
would not be a problem for me to do it through some API.
a pragmatic approach might be to preprocess the source code
and keep the original version as comments above the translated line.
(for debugging)

or to preprecess the input line before the 'exec'.

It might be, that kids are flexible enough to use English words without
understanding them.

My younger brother could write Pascal before he learnt any English and
he never cared, what 'if' 'then' 'else' 'for', etc. meant.

It might be useful though to internationalize the python errror messages
if that's not something already done.


bye


N
 
L

Luca

MRAB said:
Perhaps you could use a different extension, eg ".pyn", so existing
".py" files are handled as-is but ".pyn" files are read through a
translator.

This could be a good idea... especially since i could make my own
extension since we are talking of a special-purpose application that
only incorporates python as a library.

Thanx,
Luca
 
D

Diez B. Roggisch

And also I don't think that your concerns are valid in general.
Maybe you are right, but being italian myself i can remember when i was
a middle schooler (no computer before that) and the hours spent on my
MSX figuring out how the thing worked. I learned all the commands as
"brandnames" without really understanding them. I had _no_ idea that
"if" meant... if, or that "print" meant to print. I had zero knowledge
of english and for this reason most of these commands were meaningless
to me, i didn't even suspect they had a meaning in an existing language,
i just thought that was the way computers talked. When several years
later, in High School, i learned English it was a real surprise for me
to find out that the commands i had learned by heart as "magical words"
actually had a precise meaning in "human language" and i think this
would have helped me to figure out several things that instead took
hours or days to understand.
Now kids have internet, they study english from the kindergarten, they
have a huge quantity of manuals and books freely available, so maybe you
are right and i am just over-worrying. But still, i think it would be
nice to use a language familiar to the kid (especially very young ones),
it would make the learning process faster (no need to learn new words)
and it would make the computer feel almost like a virtual "friend".

I can't argue this from a technical point of view. Nor from a personal,
as when I was first exposed to programming, I already new a few bits &
pieces of english (leaving highschool with an E grade though....)

However, I'm pretty sure what held me back most was the lack of
(affordable, tuned to the younger audience) course material, and
exchange with peers. Both which has *massively* changed with the
internet available even in rather rural aereas of the world.

Now under the assumption that you are right here, if keywords are what
children keeps from learning programming - then your approach stops much
to early. I already mentioned the standard-library, but of course much
more important are the builtins. What's an int? Hell, I've been using
the term integer for decades now, but actually don't really know if it
really stands for "ganzzahl", the german word for what it is.

And once they learned the language from whatever course material you
prepared for them, they'd take a look outside - and find *nothing*. No
code snippet to re-use without error-prone rewriting. Lack of
understanding because of unfamiliar words. And so on.

All this with a rather high cost on your side to prepare & and maintain
a programming environment based upon a patched, potentially buggy
interpreter + assorted course material.

I really think you should instead focus on creating an environtment
similar to what squeak offers, something integrated with easy access to
graphics and sounds, that create amazement in the children and makes
them want to code to realize their dreams. And of course natively named
libraries, plus course-material. I didn't measure it, but by
guesstimation, the ratio between keywords & other literals in python
should be around the range of 1/10.

Finally - well, if I'd were to learn italian, I'd rather not have my
teacher translate all the nice italian words to german in my textbook...
;) It *is*, after all, learning a language we are talking here. It is
alien. Even python :)

Diez
 
L

Luca

News123 said:
a pragmatic approach might be to preprocess the source code
and keep the original version as comments above the translated line.
(for debugging)

Not very nice to see though. This change should be transparent to the
kid, he/she should not be aware of this "translation".
or to preprecess the input line before the 'exec'.

This could be a solution, yes, but then i would also need to figure out
a way to show the original line when debugging (still, i know nothing
about pdb, maybe it is possible in a easy way).
It might be, that kids are flexible enough to use English words without
understanding them.

My younger brother could write Pascal before he learnt any English and
he never cared, what 'if' 'then' 'else' 'for', etc. meant.

I had a similar experience. When i was a middle schooler i knew nothing
about English and so i learned Basic and then Pascal without actually
knowing that those words had a meaning at all. For me they were just
kind of "magical words" that i could use to tell the computer what to
do. So i know for sure that this is possible. But... imagine the use of
this language in a elementary school. Some kids, like me or you or your
brother would be interested enough to find it easy to learn the new
words. For others it would only be a pain. Another lesson among others
that to them makes no sense at all. If we could make it easier for them
to understand the words used in the language the teacher would have an
easier time to explain some concepts and maybe even these kids could
have fun and begin to love it.

I understand that this "breaks" the language, that it would be better if
they would just learn the "original" language... but most teachers would
ask "then why not use Logo instead? it is already in our language..."

I have nothing against logo of course, i have learned it myself even
before Pascal and i had lots of fun with it. But python is much more
widespread than logo and i think in some ways it makes "more sense" than
logo and it is not much harder. The only problem that i see is that Logo
does have its commands translated while python doesn't nor, it seems,
there is an easy way to add this functionality.
It might be useful though to internationalize the python errror messages
if that's not something already done.

Yes, this would be very important... but still, it should be easy for
the teacher to translate the messages to make them more understandable
to the kids.

For instance...

* Python:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'draw' is not defined

* Logo:
? draw
I don't know how to draw

Logo's message, while maybe too simple for a professional developer, is
certainly much more easy for a kid. So you see, it is not just a matter
of internationalization... it is also a matter of users-target. If i am
talking to a young kid i should use words and concepts that are easy for
him/her to understand... so, for my target, it would be very important
not only a correct translation in my language, but also the use of words
and concepts that are familiar to a kid.

Thanx,
Luca
 
D

Diez B. Roggisch

On a related note, did you investigate SUGAR of the OLPC? I'd say these
guys certainly tried to create something that appealed to children, and
AFAIK it comes with a Python interpreter. I'm don't know anything about
that, nor if it comes with learning material. Might be worth checking out.

Diez
 
E

Ethan Furman

Luca wrote:

[snippety]
Maybe you are right, but being italian myself i can remember when i was
a middle schooler (no computer before that) and the hours spent on my
MSX figuring out how the thing worked. I learned all the commands as
"brandnames" without really understanding them. I had _no_ idea that
"if" meant... if, or that "print" meant to print. I had zero knowledge
of english and for this reason most of these commands were meaningless
to me, i didn't even suspect they had a meaning in an existing language,
i just thought that was the way computers talked.

[more snippety]

Perhaps the lesson to learn from this is that as *you* teach programming
to non-english speakers you take the time to say "'if' means 'se',
'print' means 'stampa'", etc. I suspect your early years would have
been much easier with those bits of knowledge. :)

~Ethan~
 
L

Luca

Roald said:
I would suggest to do choose the same strategy as 'from __future__
import ...' takes, which does similar things and limits them to the
module it is used in. I would be curious to hear about your results.

Kind regards, Roald

Hi,
well, i have thought on the issue and i think that i have found a
solution that does not imply renaming the keywords. It mixes a bit the
suggestions i got here and this is how.

My application will have a text editor (with, hopefully, code
highlighting) a text-box to insert "instant" commands and a text-box for
the output and a window for the "turtle".

With the "instant commands" you can insert little pieces of python code
and see instantly their result both as a turtle movement or textual
output. With the text-editor you can load/save/write whole python
programs and execute or debug them step by step.

The way to track the code could use this technique
http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html
which gives me exactly the number of line of code under execution and
also stops the code until the function "treaceit" returns. This will
allow me to insert breakpoints, execute the code line by line, and so on
(or at least this is the theory).

Now. Since i get the number of the line i don't need anymore to have the
language deal with translated keywords. The kid can write the code in
his/her own language and the program will "translate it back to english"
before passing them to the embedded python. When i save a source file i
can save the english version and translate it "on the fly" when i load
it. I can also intercept error codes and translate them as well, showing
the kid only what i want him/her to see. So it would be completely
transparent to the kid and it would notice it only by opening the source
code via a different text-editor. In this way the files produced are
100% python files and the kid can disable this feature if he doesn't
like it. This will also allow me to translate the same piece of code in
any language i want, with 0 effort and this way will allow kids of
different nations exchange their code and have it working on their computer.

This seems a good idea to me, it reaches my points without breaking
compatibility. The kid will see the language in his own language but the
computer will actually work with the standard-python file.

Once i have this "ready" i can proceed to other steps and try to
implement other ideas that i have (remember c-robots and p-robots?).

Bye,
Luca
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top