Home > Archive > Scheme > January 2006 > Treating the user as a first class citizen
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Treating the user as a first class citizen
|
|
| bobueland@yahoo.com 2006-01-24, 9:58 pm |
| When I tried Python, the first thing I noticed is that they were
treating me as a first class citizen. Take introspection for instance,
see below for details. The role of the computer is not just to
interpret the source code but also to assist user in remembering all
the nasty details.
When I write "help" in DrScheme it says
> help
reference to undefined identifier: help
Let me take one example. If I want to know all the primitive precedures
in Python I write[color=darkred]
and Python spits out all the primitive procedures. If I want to know
all the primitive procedures in Scheme, what do I do? (If you know
please let me know because I've been looking for it).
Now I know that there is help documentation, elsewhere. So have other
languages including Python. But I think Pythonians went a step further
and made the help available directly in the shell. That is one example
of treating the user as a first class citizen. There are others. Now
the important thing is that I think that Pythonians are asking the
question "How can we make it easier for the programmer" all the time.
And I think more language designers should put that question on the top
of their "to do" list.
Bob
----- A snapshot of Pythons introspection features -------
---Bob: I'm opening the shell and writing help. This happens[color=darkred]
Type help() for interactive help, or help(object) for help about
object.
---Bob: I write help(). This happens[color=darkred]
...
Enter the name of any any module, keyword, or topic ..
To quit just type "quit".
To get a list of available modules, keywords, or topics, type
"modules", "keywords", or "topics". To list the modules whose
summaries contain a given word such as "spam", type "modules spam".
---Bob: I write keywords. This happens
help> keywords
Here is a list of the Python keywords. Enter any keyword to get more
help.
and else import raise
assert except in return
break exec is try
class finally lambda while
continue for not yield
def from or
del global pass
elif
---Bob: I write topics. This happens
help> topics
Here is a list of available topics. Enter any topic name to get more
help.
ASSERTION DELETION LOOPING SEQUENCES
ASSIGNMENT DICTIONARIES MAPPINGMETHODS SHIFTING
ATTRIBUTEMETHODS DICTIONARYLITERALS MAPPINGS SLICINGS
ATTRIBUTES DYNAMICFEATURES METHODS
SPECIALATTRIBUTES
AUGMENTEDASSIGNMENT ELLIPSIS MODULES
SPECIALIDENTIFIERS
BACKQUOTES EXCEPTIONS NAMESPACES
SPECIALMETHODS
BASICMETHODS EXECUTION NONE
STRINGMETHODS
BINARY EXPRESSIONS NUMBERMETHODS STRINGS
BITWISE FILES NUMBERS SUBSCRIPTS
BOOLEAN FLOAT OBJECTS TRACEBACKS
CALLABLEMETHODS FORMATTING OPERATORS TRUTHVALUE
CALLS FRAMEOBJECTS PACKAGES
TUPLELITERALS
CLASSES FRAMES POWER TUPLES
CODEOBJECTS FUNCTIONS PRECEDENCE TYPEOBJECTS
COERCIONS IDENTIFIERS PRINTING TYPES
COMPARISON IMPORTING PRIVATENAMES UNARY
COMPLEX INTEGER RETURNING UNICODE
CONDITIONAL LISTLITERALS SCOPING
CONVERSIONS LISTS SEQUENCEMETHODS1
DEBUGGING LITERALS SEQUENCEMETHODS2
---Bob: I write modules. This happens
help> modules
ArgImagePlugin WbmpImagePlugin foo
sre_constants
AutoExpand WidgetRedirector formatter sre_parse
BaseHTTPServer WindowList fpformat sspi
Bastion WmfImagePlugin ftplib sspicon
... (and so on in total 561 modules)
---Bob: I write ftplib. This happens
help> ftplib
Help on module ftplib:
NAME
ftplib - An FTP client class and some helper functions.
FILE
c:\python24\lib\ftplib.py
DESCRIPTION
Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J.
Reynolds
Example:
[color=darkred]
'230 Guest login ok, access restrictions apply.'[color=darkred]
total 9
drwxr-xr-x 8 root wheel 1024 Jan 3 1994 .
drwxr-xr-x 8 root wheel 1024 Jan 3 1994 ..
... (and so on, about 4 pages of help information)
---Bob: I write quit. This happens
help> quit
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
---Bob: I write dir(). This happens (showing me the current
environment)[color=darkred]
['__builtins__', '__doc__', '__name__'][color=darkred]
---Bob: I write dir(__buitins__). This happens[color=darkred]
['ArithmeticError', 'AssertionError', 'AttributeError',
'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError',
'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'IOError',
'ImportError', 'IndentationError', 'IndexError', 'KeyError',
'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None',
'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError',
'OverflowWarning', 'PendingDeprecationWarning', 'ReferenceError',
'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration',
'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit',
'TabError', 'True', 'TypeError', 'UnboundLocalError',
'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError',
'UnicodeTranslateError', 'UserWarning', 'ValueError', 'Warning',
'WindowsError', 'ZeroDivisionError', '_', '__debug__', '__doc__',
'__import__', '__name__', 'abs', 'apply', 'basestring', 'bool',
'buffer', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile',
'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod',
'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float',
'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex',
'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter',
'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min',
'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range',
'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set',
'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super',
'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
---Bob: I write help(range). This happens[color=darkred]
Help on built-in function range in module __builtin__:
range(...)
range([start,] stop[, step]) -> list of integers
Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to
0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is
omitted!
These are exactly the valid indices for a list of 4 elements.
---Bob: I write dir(ftplib). This happens[color=darkred]
['CRLF', 'Error', 'FTP', 'FTP_PORT', 'MSG_OOB', 'Netrc', '_150_re',
'_227_re', '__all__', '__builtins__', '__doc__', '__file__',
'__name__', 'all_errors', 'error_perm', 'error_proto', 'error_reply',
'error_temp', 'ftpcp', 'os', 'parse150', 'parse227', 'parse229',
'parse257', 'print_line', 'socket', 'sys', 'test']
---Bob: I write help (ftplib.os). This happens[color=darkred]
Help on module os:
NAME
os - OS routines for Mac, DOS, NT, or Posix depending on what
system we're on.
FILE
c:\python24\lib\os.py
... (and so on, 8 pages of help information)
| |
| Lauri Alanko 2006-01-24, 9:58 pm |
| In article <1138115852.155047.57690@z14g2000cwz.googlegroups.com>,
<bobueland@yahoo.com> wrote:
> and Python spits out all the primitive procedures. If I want to know
> all the primitive procedures in Scheme, what do I do? (If you know
> please let me know because I've been looking for it).
In PLT Scheme: (namespace-mapped-symbols (make-namespace 'initial))
Lauri
| |
| bobueland@yahoo.com 2006-01-24, 9:58 pm |
| Thanks Lauri, it works.
| |
| bobueland@yahoo.com 2006-01-24, 9:58 pm |
| There were 968 primitive procedures(Oh boy, I didn't know they were so
many). Now all of them can't be primitive in 'basic-primitive' sense.
For instance (positive? n) can be expressed as (> n 0). In R5RS (if I
remember correctly) they say that positive? is a library procedure,
that meaning that it is bult out of 'basic-primitive' procedures. Is
there a way of listing only those 'basic-primitive' procedures?
| |
| Anton van Straaten 2006-01-24, 9:58 pm |
| bobueland@yahoo.com wrote:
> There were 968 primitive procedures(Oh boy, I didn't know they were so
> many). Now all of them can't be primitive in 'basic-primitive' sense.
> For instance (positive? n) can be expressed as (> n 0). In R5RS (if I
> remember correctly) they say that positive? is a library procedure,
> that meaning that it is bult out of 'basic-primitive' procedures. Is
> there a way of listing only those 'basic-primitive' procedures?
No, there's no way to do that. Primitives as defined by R5RS are
"logically" primitive, and don't necessarily correspond to the
primitives in a particular implementation of Scheme. For example,
whether IF or COND is primitive isn't all that important, since either
can be implemented in terms of the other.
Further, the logical notion of "primitive" is relatively meaningless in
an actual implementation of Scheme. What's usually considered primitive
in an implementation is simply those procedures that are not implemented
in Scheme, but rather in the underlying host language, such as C.
As an example of the latter kind of primitives, and following from
Lauri's example, you can find out which procedures PLT considers
primitive in the sense that they are "implemented in low-level
languages" (see the PLT Help Desk, section 3.12.2, "Primitives"). The
following code will list the procedures that respond to PLT's PRIMITIVE?
predicate with #t. There are 810 of them.
(require (lib "list.ss"))
(filter
(lambda (s)
(primitive? (namespace-variable-value s #t (lambda () #f))))
(namespace-mapped-symbols (make-namespace 'initial)))
However, there aren't many valid uses for this list unless you're doing
some kind of low-level extension or extreme performance optimization.
If you're looking for a list of procedures that are important to learn
about, I'd recommend working through the book at htdp.org, which tells
you which things are important to learn about in the exact sequence that
it's important to learn about them. :)
Anton
| |
| bobueland@yahoo.com 2006-01-24, 9:58 pm |
| Anton van Straaten wrote:
> If you're looking for a list of procedures that are important to learn
> about, I'd recommend working through the book at htdp.org,
Yes Anton, that was exactly what I was looking for. When learning to
play guitar I looked thrugh the song books and made a frequency table
of the chords and made a list that looked something like D-major,
G-major, A-minor, etc. So I started by learning D-major and G-major,
and there were lot of songs I could play with thus two chords.
I would like to have such a list for Scheme but I don't want to wade
through a whole book to sift it out. I feel that HTDP is a very good
book, but was written for beginners and litlle to long-winded for me.
If I don't find the book which feels right I rather make ny own path,
and in that case the frequency list comes handy.
Bob
| |
| Anton van Straaten 2006-01-24, 9:58 pm |
| bobueland@yahoo.com wrote:
> Anton van Straaten wrote:
>
>
>
>
> Yes Anton, that was exactly what I was looking for.
....
> I would like to have such a list for Scheme but I don't want to wade
> through a whole book to sift it out.
In that case, R5RS is probably your best bet. However, keep in mind
that R5RS embodies the entire core of Scheme, which includes advanced
features which can take years to come to grips with.
> I feel that HTDP is a very good
> book, but was written for beginners and litlle to long-winded for me.
> If I don't find the book which feels right I rather make ny own path,
> and in that case the frequency list comes handy.
You might try skimming a book like HtDP (or some other book more to your
taste - see http://community.schemewiki.org/?category-texts ), and just
trying to do the exercises. When you come across an exercise you can't
do, backtrack through the book to find out what you need.
The reason I suggest this is that your previous experience with
imperative languages, whether Python or any other, is in many respects a
poor guide for learning a language like Scheme. (I say this from
personal experience.) It's a good idea to take some guidance from a
source which will teach you important concepts that you might otherwise
miss completely, if you're just focusing on treating Scheme as a
collection of primitive procedures which can be combined in the ways
you're already used to.
Anton
| |
| bobueland@yahoo.com 2006-01-24, 9:58 pm |
| Anton van Straaten wrote:
>You might try skimming a book like HtDP
I tried to follow this advice and I'm glad I did. HTDP is a *very* good
book even for non-beginners if you use it the right way.
Bob
|
|
|
|
|