function,lisp,common-lisp , How to use do in lisp?


How to use do in lisp?

Question:

Tag: function,lisp,common-lisp

What I'm trying to do is to write a function that which will restart a game of tic-tac-toe after it ends. What is supposed to happen is that the player will be asked if they want to play another game. If they do, then they click yes and a function is called that will start the game over. If they choose no, then the program terminates. Here is what i have so far...

(defun play-again ()
  (do (y-or-n-p "Would you like to play again? ")
      ((play-one-game) nil)))

The play-one-game is the function that i want to run if the user clicks"yes" from the prompt. Otherwise the game terminates since no other function is called. By the way, just in case you need to know, i am using Allegro.


Answer:

Assuming your y-or-n-p nil only when the user pressed n you could write your main loop as

(defun main ()
  (loop :while (y-or-n-p "Would you like to play again? ")
        :do (play-one-game)))

or at the end of play-one-game, which I would rename play, prompt the user and if he wants to play again just call play one more time.

(defun play-one-game ()
  ....
  (when (y-or-n-p "Would you like to play again? ")
    (play-one-game)))

Related:


Get array output of one function in another function php


php,function,codeigniter
I have below controller function of codeigniter, public function add_attachments($openid) { $config = array( 'upload_path' => './uploads/attachments/', 'allowed_types' => 'gif|jpg|png|jpeg|doc|pdf', 'max_size' => '1024000000', 'multi' => 'all' ); $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); } else { $data = $this->upload->data(); } $new_array = array_column ($data,...

Stopping condition on a recursive function - Haskell


string,function,haskell,if-statement,recursion
So, I have this function which aims to align the text on the left without cutting words(only white spaces). However my problem is that I cannot find a stopping condition of the function and it goes infinitely. f n "" = "" --weak condition f n s = if n...

Why can we use undefined object in Javascript function declaration?


javascript,function
Chromium WebUI has a cr.js file, which offers cr.define( name, fun ) method, for modulization. All the porperties of the object that fun returns, will be added to the name namescope object. In chromium browser bookmarks manager page(chrome://bookmarks), a Javascript source file named bmm.js is loaded. This is a Javascript...

Calling function and passing arguments multiple times


python,function,loops
I want to call the function multiple time and use it's returned argument everytime when it's called. For example: def myfunction(first, second, third): return (first+1,second+1,third+1) 1st call: myfunction(1,2,3) 2nd call is going to be pass returned variables: myfunction(2,3,4) and loop it until defined times. How can I do such loop?...

How can I simulate a nested function without lambda expressions in C++11?


c++,function,c++11,lambda,allegro
I have the following code: int main(int argc, char **argv) { App app(800, 600); app.add_event_scene(Scene("Event Plot", event_plot)); Image x("sample.png"); struct foo { static void visual_plot() { x.draw(); } }; // Error. app.add_visual_scene(Scene("Visual Plot", foo::visual_plot)); app.run(); return 0; } And I get the following error: ||=== Build: Debug in Joy-Plus-Plus (compiler:...

Counting bytes received by posix read()


c,function,serial-port,posix
I get confused with one line of code: temp_uart_count = read(VCOM, temp_uart_data, 4096); I found more about read function at http://linux.die.net/man/3/read, but if everything is okay it returns 0, so how we can get num of bytes received from that? temp_uart_count is used to count how much bytes we received...

Python avoid item = None in a request of multiple items


python,function,request,urllib,nonetype
I'm doing a loop for multiple requests on a web database, each time it takes one geneId to request it to the database. If the geneId is referenced I can use the data I get for another request on a second database. But if the geneId is not referenced, it...

How to return an array with unhappy numbers removed?


matlab,function
I'm quite new to using MATLAB, and am still trying to understand how to make this particular function. I understand the formula for performing this on paper, but I'm having trouble translating it into the required MATLAB syntax. How would a function be written such that it takes an array...

MySQL function with parameters syntax error


mysql,regex,function
I'm trying to convert this query to a MySQL function SET @v1 := ( SELECT count(id) as count FROM article_category where (title like "About Usd") or (title like "About Usd-%" and title regexp '[0-9]$') ); INSERT INTO `article_category` (`title`,`meta_data`,`meta_description`) VALUES ( IF(@v1 <= 0, "About Usd", CONCAT("About Usd","-",@v1) ), "ddddD",...

PercentOfSum(fld, condfld) SSRS Equivalent


function,reporting-services,crystal-reports,ssrs-2008,ssrs-2008-r2
Crystal Reports has a built-in function PercentOfSum(fld, condfld) (documentation here). How can I achieve the same functionality in SSRS?

XQuery - Doing math on elements within a sequence and aggregating results


function,operators,xquery,sequence,aggregation
I'm trying to execute a XQuery sum function in a multiplication of two XML elements, but it has been difficult to avoid the iteration in a sequence of elements. For example, consider this case: sample data: <Orders> <Order> <OrderKey>1</OrderKey> <LineItem> <LineNumber>1</LineNumber> <Quantity>41</Quantity> <ExtendedPrice>70848.0000</ExtendedPrice> <Discount>0.0913</Discount> <Tax>0.0663</Tax> <ReturnFlag>A</ReturnFlag>...

JSLint won't recognize getElementById


javascript,function,getelementbyid,jslint
JSLint gives errors with simple function, running on brackets with JSLint. Javascript: function soundSorry() { getElementById("player").play(); } Error codes: 2 Missing 'use strict' statement. getElementById("player").play(); 2 'getElementById' was used before it was defined. getElementById("player").play(); Any ideas?...

EVAL/APPLY: too many arguments given to F


lisp,common-lisp,clisp
Hello why do i get *** - EVAL/APPLY: too many arguments given to F on function call with nested lists parameter. I cannot figure it out, since I passed a simple nested list. (defun f (L) (cond ((NULL l) nil) ((listp (car L)) (append (F(car L))) (F(cdr L) (car (F...

How can I minimize this function in R?


r,function,optimization,mathematical-optimization
I'm attempting to write a formula that will determine a value of a that minimizes the function output myfun (i.e. a-fptotal). MWE: c <- as.matrix(c(.25,.5,.25)) d <- as.matrix(c(10000,12500,15000)) e <- 700 f <- 1.1 tr <- .30 myfun <- function(a) { b <- max(a-e,0) df <- data.frame(u1=c(c*b*.40),u2=c(c*b*.60)) df$year <- 1:nrow(df)...

Toggle text + also call method with argument?


jquery,function,toggle
Im trying to toggle change a text on spacebar press with jquery ( works ) but also try to call a method with custom argument. How would below code example needs to me modified to do this? I have tried all kinds of ways but don't understand how to add...

How do I return a value from a second function in PHP?


php,function,return,value
I'm a green green newbie trying to write a simple program in PHP. I use an HTML form to ask a "diner" to select an entree, which sends the choice to a PHP program.The PHP program is supposed to echo the entree choice, suggest a drink to the diner, and...

Update input number variable onclick


javascript,jquery,html,function
I am trying to create a calculator style thing, where you put in how many years into a input, you hit submit and it gives you different results below without reloading the page. I have all the calculations working right now, but I just cant get the input number variable...

function pointer is not a function or function pointer


c++,function,pointers
I have following problem: void MyClass::LoopFunction(vector<Item>& items,void (MyClass::*funcy)(vector<Item>&,int)) { for(SInt32 i = 0; i < 50; i++) { funcy(items,i); } } It says: Called object type 'void(MyClass::*)(vector<Item>&,int)' is not a function or function pointer Can anyone help me to find a solution for this?...

How to pass pointer to struct to a function?


c,function,pointers,struct
I am instantiating the struct within the main() function and I am passing a pointer to this structure over to a function. I would like to then pass this pointer to the original struct to another function, how would I do this? I am now lost in pointerception. struct coords...

Is it possible to use $(this) in a function called from another function?


jquery,function,this
Sorry for the question title, I know it's not very well worded, but I couldn't really explain what I'm asking in a summary. I have a JQuery function tied to the click event of an element. For reasons that may well be flawed (other than making more sense to me...

A function to calculate cumulative maximum for a double matrix in MATLAB


matlab,function,matrix,max
Is there any function that can calculate cumulative maximum for a double matrix? I have a 1*3000 matrix and I need to calculate the cumulative maximum. For example if the matrix is: A = [8 3 6 7 9 10 6 2 2 3] The cumulative maximum array will be:...

Why doesn't this swift function work?


string,function,swift
This function takes two string arguments. It is supposed to return the first one as dashes except where the character is somewhere inside of the second argument. Example: dashes_except("hello", except: "lo") -> --llo The function works fine when the except argument is only one letter but fails when it is...

Selecting and removing a html select option without selecting by index or ID, using vanilla JavaScript


javascript,function,select,options
I need to remove an option on a select box, and I've figured out a potential solution in the code below, but it doesn't feel particularly 'safe' (if another developer decided to add an option to the backend, the option will re-appear). Is there a better way of achieving this...

is return main(); a valid syntax?


c,function,return,language-lawyer,return-type
I found some interesting code lines: #include <stdio.h> int main() { printf("Hi there"); return main(); } It compiles ok (VS2013) and ends up in stackoverflow error because of the recursive call to main(). I didn't know that the return statement accepts any parameter that can be evaluated to the expected...

How do I fix function compilation error?


oracle,function,plsql,sql-update
--this is my function create or replace function sal_incr ( p_grade number) return number is v_inc number; begin select raise_percent into v_inc from sal_inc where grade_id in (select grade_id from emp_task where grade_id = p_grade); return v_inc; end; -- Update statement update emp_task set sal = sal + sal_incr(grade_id); --...

Call known function (with parameters) in class whose name is defined by string variable


java,function,class,variables
I have a bunch of classes of various names and each has a performLogic function that accepts a number of preset parameters (always the same): public final class DoSomeAction extends SetupAction { public void performLogic(param1, param2... I want a way where I can call it like this: String actionName =...

Can't understand this Javascript function (function overloading)


javascript,function,methods,overloading
I'm reading Secrets of Javascript Ninja and came across an example that I cannot fully understand. This same example was cited by some other user here before, but their doubts are different than mine. Here is the example: function addMethod(object, name, fn) { var old = object[name]; object[name] = function(){...

How to call a data.frame inside an R Function by name


r,function,data.frame,call
I want to write a function that runs the same analysis on different data.frames. Here is a simple version of my code: set1 <- data.frame(x=c(1,2,4,6,2), y=c(4,6,3,56,4)) set2 <- data.frame(x=c(3,2,3,8,2), y=c(2,6,3,6,3)) mydata <- c("set1", "set2") for (dataCount in 1:length(data)) { lm(x~y, data=mydata) } How do I call a data.frame by name...

C# add to list not working


c#,function
I am new to C# and I am just trying to create a simple program to perform some basic calculations on VS2010. The problem I'm having is that I don't seem to be able to add the calculated value to a list. List<double> distance = new List<double>(); List<double> speed =...

My is_prime function fails on 9, and I don't know why?


python,function
I have a bit of a problem. I am writing an is_prime function on, but whenever I run it, it fails on is_prime(9), and I cannot see why: def is_prime(x): if x < 2: ##because negative numbers, 0 and 1 are not prime## return False elif x == 2: return...

C++ need help figuring out word count in function. (Ex. Hello World = 2)


c++,function
I'm figuring out the algorithm on this function and it keeps crashing at runtime, here's the code snippet: int wordCounter(char usStr[]) { int index= 0, punct= 0; while(usStr[index]!= '\0') //If it's not the end of the sentence if(usStr[index]== ' ') //If it finds a space index++; while(usStr[index]== '\0') //If it's...

strip_tags() on MySQLi Query and PHP Function [closed]


php,mysql,string,function,mysqli
I'm trying hard to learn how to create functions, and I don't know what I'm doing wrong here. Could someone explain it to me please? I'm not using strip_tags(), why it's getting me this error? I don't need it to return, I just to need to update database if $xp...

Global scope for array of structs inside function - Swift


arrays,function,swift,struct,shuffle
I would like to shuffle my array questions and use the shuffled array in the program when it starts. I have created this function that shuffles the array. func shuffleQuestions() { var shuffledQuestions = shuffle(questions) } This gives me an array with questions shuffled that inherits the values from the...

Casting a String Into a Function in R


r,function,casting
I have a Shiny app in R where I want users to be able to create functions on the fly by entering text in a text box. To enable this functionality, I would like to know the following: How would I go about casting a string object containing a function...

How to skip a function


function,python-2.7
I am learning python and trying to make a little game. So my question is can you define a function but skip it and use it later. EX. def func() print"1,2,3,4" func() def func2() print "counting" func() func2() How would I skip func but still be able to print it...

Insertion into a list doesn't reflect outside function whereas deletion does?


list,lisp,common-lisp
I am new to Lisp. Deletion of an item in a list by a function gets reflected outside the function but insertion doesn't. How can I do the same for insertion? For example (defun test (a b) (delete 1 a) (delete 5 b) (append '(5) b) (member '5 b)) (setq...

session value in javascript cannot be set


javascript,function,session
I am quite new to javascript, I wonder why my session value in javascript wont be set to 1 even I tried. When call this function again, the value of the session will change again. My javascript code as below. <script type="text/javascript"> function Confirm() { alert(<%=Session["Once"]%> != 1); var value...

Replace paragraph in HTML with new paragraph using Javascript


javascript,function,onload,getelementbyid,appendchild
I am attempting to replace a p in my HTML doc with a paragraph created in Javascript. Once the page loads, two will be replaced with t. var two = document.getElementById("two"); document.onload = function myFunction() { var p = document.createElement("p"); var t = document.createTextNode("I am the superior text"); p.appendChild(t); document.getElementById("p");...

SQL average age comparison function returns null


mysql,sql,function,datetime
So, I'm working in MySQL, writing a function that averages the ages of women and men from a table and compares them, and returns which is greater. Dates are in the format of YYYY-MM-DD, and I'm using DATEDIFF(). The function appears to work correctly, but when I run the script,...

Stuck on Structs(c++)


c++,function,struct
Okay so this is what Ive been asked to do "make a struct called Coordinate that contains the latitude and longitude of a point on the surface of the Earth. The struct should also store a label or name for the coordinate (e.g., “Calgary”). Both the latitude and longitude member...

Interpret formulae/operators as functions


r,function,variable-assignment,formula,evaluation
Is it possible in R to assign custom functions to mathematical operators (eg. *, +) or interpret the formulae supplied with as.formula() as a directive to evaluate? Specifically, I would like * to be interpretted as intersect(), and + as c(), so R would evaluate the expression (a * (b...

JavaScript recursive function breaks when () included in call


javascript,jquery,function
I have created a countdown "Pomodoro" timer using JavaScript and JQuery. The code snippet I am referring to is the following: var time = 1500; var cycle = "long"; var tracker = 0; var paused = false; //Timer countdown function function countdown(){ if (!paused) { var seconds = ("00" +...

Can anyone improve on the below Fuzzyfind function for VBA?


algorithm,vba,function,find,fuzzy-search
This function lets you find similar strings from a range without having to do an exact search. The formula looks like this: =FuzzyFind(A1,B$1:B$20) assuming the string you are performing a search for is in A1 and your reference or options table is B1:B20 The code is here: Function FuzzyFind(lookup_value As...

jQuery - Value in Function


jquery,arrays,function
My array: array.name = "Thiago"; array.date = "01/01/1990"; I want a function like this: function myFunc( array, fieldToCompare, valueToCompare ) { if( array.fieldToCompare == "Thiago" ) alert(true); } myFunc( myArray, name, "Thiago" ); is it possible?...

Decremented value called in the recursion in Haskell


string,function,haskell,recursion,parameters
So, I have this function that aligns the text to the left for a given column width. I have already fixed some of its problems, but I am unable to make it not use the decremented parameter once it is called, but to return to the starting value of n....

sum of Digits through Recursion


java,function,recursion,sum,digit
I am trying to make a recursive function which should return the sum of digits. The function should have only one argument. So far I have this; public int sumDigits(int n) { if(n%10 == n) // last digit remains return n; else{ int rightdigit; rightdigit = n%10; // taking out...

My function will log a value to the console, but it won't return the same value - why? [duplicate]


javascript,arrays,function,recursion
This question already has an answer here: Return value of recursive function is 'undefined' 1 answer I've created the following function to flatten a nested array: function steamroller(arr) { arr = arr.reduce(function(a, b, i){ return a.concat(b); },[]); if (!Array.isArray(arr[arr.length-1])) {console.log(arr); return arr;} steamroller(arr); } steamroller([1, [2], [3, [[4]]]]); The...

Delete file after “x” second after creation


vb.net,function
I want to delete file after 15 second of create that file. I use this code but no success. Private Sub Form1_Click(sender As Object, e As EventArgs) Handles Me.Click Dim test = Application.StartupPath & "\" + tte4 Timer1.Enabled = True If Timer1.Interval = 0 Then My.Computer.FileSystem.DeleteFile(test) End If End Sub...

How does ((a++,b)) work? [duplicate]


c,function,recursion,comma
This question already has an answer here: What does the comma operator `,` do in C? 8 answers In the below block of code, I am trying to understand how the line return reverse((i++, i)) is working. #include <stdio.h> void reverse(int i); int main() { reverse(1); } void reverse(int...

Genetic Algorithm - convergence


java,algorithm,function,genetic-programming,convergence
I have a few questions about my genetic algorithm and GAs overall. I have created a GA that when given points to a curve it tries to figure out what function produced this curve. An example is the following Points {{-2, 4},{-1, 1},{0, 0},{1, 1},{2, 4}} Function x^2 Sometimes I...