Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typo and unclear exercise #3

Open
Anniepoo opened this issue Jan 20, 2014 · 1 comment
Open

typo and unclear exercise #3

Anniepoo opened this issue Jan 20, 2014 · 1 comment
Assignees

Comments

@Anniepoo
Copy link
Owner

these from Ben Engbers

********* typo
1_3 Defining new abstract paths
First a typo: (word 'tryig' should be trying)

******************* confusing point
A warning of a confusing point. I was trying to make ..

"I was tryig to make these 'abstract paths' be abstract files paths for a long time when learning this stuff."
I understand the concept of abstract paths but what do you mean when you talk of 'abstract files'?

************ confusing exercise
Exercise 2: Add a handler that says 'sorry, not here' to 1_3 when you try something like http://127.0.0.1:8000/this/is/invalid

I am trying to add the 404-handler but even after googling a lot I haven't come any further.
I assume that I will have to use http_error and expect to see a stack-trace but even after loading that module, I get a standard page that says that http://127.0.0.1:8000/does/not exist cannot be found.

I only found one example-program (calc.pl) that seems to use http_error.

Can you supply a clue on how to tackle this exercise?

@ghost ghost assigned Anniepoo Jan 20, 2014
@Anniepoo
Copy link
Owner Author

I'll definitely expand that section of the tutorial.
An 'Abstract file path" is called a 'path alias' at various places in the SWI-Prolog documentation. Admittedly, it's hard to find
documentation of this - I've filed SWI-Prolog bug #156 against that.
Anyway, most places where a file name is called for in SWI-Prolog will take a 'file alias'. For example, when you use library
modules you write
:- use_module(library(lists)).

library(lists) means 'the module lists, which by convention is in the file lists.pl, in the abstract path library. The path library has been defined somewhere by calling file_search_path, which relates an
absolute path to a file alias. So, suppose you are writing a program and want to refer to some test
images that are in the /testimages directory. You could define a path alias

user:file_search_path(test, '/testimages').

and now open one of these images named test0.png with
open(test('test0.png'), read, Stream, [type(binary)])

Now, your coworker's not happy with putting the test images in the root of the file system, and has hers in /home/coworker/test/images. She can change the alias in one place and not have to trace down every reference to the path. BUT, there's an easier way....
the file search path looks through all the paths for the file. So she can just add her configuration to the search

user:file_search_path(test, '/testimages'). % Ben Engbers path
user:file_search_path(test, ' /home/coworker/test/images'). % Sally Coworker path

And the system ignores the nonexistant path on her machine, and similarly on yours.

Now later on you get a lot more test images. Nobody wants all those images on their local machine,
so everybody mounts an NFS mount on the server. But people are working on various problems,
and still have local images they want added to the test set.

user:file_search_path(test, '/testimages'). % Ben Engbers path
user:file_search_path(test, ' /home/coworker/test/images'). % Sally Coworker path
user:file_search_path(test, '/mnt/images'). % the image server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant