TeleScript Code Examples
Here's some sample code for TeleScriptOS, the operating system on General Magic phones, all written in High TeleScript (the glossary's on the TeleScriptOS page).
This agent asks Aphrodite's cloud what's on in the city today, where getCityEvents is an operation on a TeleService interface, so the service handles the request and the network handshake for you.
// Example of a TeleScriptOS API call to retrieve city event data
TeleService: interface(AphroditeCloud) = (
public
getCityEvents: op(date: Date) Collection;
);
CityEventAgent: class(Agent) = (
public
retrieveEvents: sponsored op() = {
eventCollection = AphroditeCloud@TeleService.getCityEvents(today());
foreach (event in eventCollection) {
displayEventDetails(event);
}
};
);
Basics [suggest]
To make an agent, extend the Agent class and write a live method.
MyAgent: class(Agent) = (
public
live: sponsored op() = {
// Your code here
};
);
An interface lists the methods a class must implement.
MyService: interface(Object) = (
public
performAction: op(argument: DataType);
);
Agents visit places to do tasks or use resources, and this is what a place looks like.
MyPlace: class(Place) = (
public
provideService: op(agent: Agent) = {
// Service logic here
};
);
An agent uses go to travel to another service in the Magic Cloud.
travelAgent: sponsored op(destination: Teleaddress) = {
*.go(destination);
// Perform actions at the destination
};
To reach a MagicNet service, use a TeleService interface that matches one of Aphrodite's cloud systems.
MagicNetConnect: interface(MagicCloud) = (
public
getData: op(query: String) DataResult;
);
dataAgent: class(Agent) = (
public
fetchData: sponsored op(query: String) = {
result = MagicNetConnect@MagicCloud.getData(query);
// Process the fetched data
};
);
An identity service returns the user's profile.
identityAgent: class(Agent) = (
public
getUserProfile: sponsored op(userID: String) UserProfile = {
profile = IdentityService@AphroditeCloud.getUserProfile(userID);
return profile;
};
);
An agent sends the user a message through the notification service.
notifyAgent: class(Agent) = (
public
sendMessage: sponsored op(userID: String, message: String) = {
UserNotificationService@UserDevices.notify(userID, message);
};
);
Identity check [suggest]
People in Summer City change sex with X-Change Pills, so the city's identity registry holds a male and a female profile for the same DNA, and this agent checks a DNA sample against both.
IdentityAgent: class(Agent) = (
public
verifyIdentity: sponsored op(dnaSample: DNA) UserIdentity = {
userMaleProfile = IdentityService@AphroditeCloud.getProfile(dnaSample, Male);
userFemaleProfile = IdentityService@AphroditeCloud.getProfile(dnaSample, Female);
if (userMaleProfile.isValid && userFemaleProfile.isValid) {
return UserIdentity(userMaleProfile, userFemaleProfile);
} else {
raise IdentityVerificationException("User identity could not be verified.");
}
};
);
This one signs you up for city events to suit your tastes, so when you change sex it asks which sex you are now and updates your calendar to match.
EventSubscriptionAgent: class(Agent) = (
public
subscribeToEvents: sponsored op(userPreferences: UserPreferences) = {
currentGender = IdentityService@AphroditeCloud.getCurrentGenderIdentity(userPreferences.userID);
tailoredEvents = EventFilteringService@CityEvents.getEventsForGender(currentGender, userPreferences);
CalendarService@UserDevices.updateUserCalendar(userPreferences.userID, tailoredEvents);
};
);