Ex3 lisp likelist in java

3,098 views

Published on

Published in: Technology, Education
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
3,098
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
34
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Ex3 lisp likelist in java

  1. 1. 3.Implementation of Lisp_like list in javaAIM: To write a java program to implement the lisp_like list in java.ALGORITHM: 1.To implement the necessary packages needed. 2.Implement the lisp_like list in java to perform functions like thatcar(),cdr() 3.Car() function  The car of a list is, quite simply, the first item in the list.  Thus the car of the list (rose violet daisy buttercup) is rose.Example: (car (rose violet daisy buttercup)) •After evaluating the expression, rose will appear in the echo area. 4.Cdr() function •The cdr of a list is the rest of the list, that is, the cdr function returns the part of the list that follows the first item.Example: (cdr (rose violet daisy buttercup)) •When you evaluate this, (violet daisy buttercup) will appear in the echo area. 5.To create a arraylist and add the integer values 6.To perform the car()&cdr() functions in above method ; 7.Print the outputs and terminate the program.PROGRAM:import java.util.*;/**
  2. 2. * @version 1.6.0* @author Annal Sheeba Rani*///To create a class Lisp using to perfom car()&cdr()functionspublic class Lisp {//To perform car() functionpublic int car(List l){Object ob=l.get(0);String st=ob.toString();System.out.println("Using a L.car() function");return Integer.parseInt(st);}//To perform cdr() functionpublic List cdr(List l){Object ob=l.remove(0);Object obj[]=l.toArray();System.out.println("Using a L.cdr() function");List list=Arrays.asList(obj);return list;}public static void main(String[] args){// To add the integer value in the ArrayListList<Integer> l=new ArrayList<Integer>();l.add(3);
  3. 3. l.add(0);l.add(2);l.add(5);//To print the Return values of Car(),Cdr()functionsLisp L=new Lisp();int val=L.car(l);System.out.println(val);List list=L.cdr(l);System.out.print(list);}}OUTPUT:Using a L.car() function3Using a L.cdr() function[0, 2, 5]

×