what is the meaning of _! and _?

1 view
Skip to first unread message

harmanjd

unread,
Jan 8, 2010, 2:54:35 PM1/8/10
to Lift
I am reading through the lift book to start getting an understanding
of lift.

I saw code like this

override def readPermission_? = true
override def writePermission_? = true
protected def i_obscure_!(in : BigDecimal) = defaultValue
protected def real_i_set_!(value : BigDecimal): BigDecimal = {
if (value != data) {
data = value
dirty_?(true)
}
data
}


My question is if there is some implied meaning by ending a field in
_! or not? It seems confusing as a newbie to have that when scala has
an _ operator and a _*. I got confused with names like 'dirty_?'
and have to think 'is that an operator of some sort that I need to
lookup or is that just a name?

Thanks,
James

Jim Wise

unread,
Jan 8, 2010, 3:12:48 PM1/8/10
to lif...@googlegroups.com
harmanjd <harm...@gmail.com> writes:

> My question is if there is some implied meaning by ending a field in
> _! or not? It seems confusing as a newbie to have that when scala has
> an _ operator and a _*. I got confused with names like 'dirty_?'
> and have to think 'is that an operator of some sort that I need to
> lookup or is that just a name?

Can't speak for their specific etymology in lift, but this kind of usage
of '?' and '!' has a long history in other functional languages.

Scheme, in particular, has a strong convention that a predicate (no side
effects, returns a boolean answering questions about a piece of data
ends in '?', and an imperative or destructive operation (changes a piece
of data in-place, instead of returning a new object and is thus execute
for its side effects), ends in '!'.

The addition of '_' in lift is stylistic, I guess...

--
Jim Wise
jw...@draga.com

David Pollak

unread,
Jan 8, 2010, 3:14:09 PM1/8/10
to lif...@googlegroups.com
On Fri, Jan 8, 2010 at 11:54 AM, harmanjd <harm...@gmail.com> wrote:
I am reading through the lift book to start getting an understanding
of lift.

I saw code like this

override def readPermission_? = true
override def writePermission_? = true
protected def i_obscure_!(in : BigDecimal) = defaultValue
protected def real_i_set_!(value : BigDecimal): BigDecimal = {
if (value != data) {
data = value
dirty_?(true)
}
data
}



Something that ends in _? should return a Boolean (readPermission_? looks more natural to me than hasReadPermission)

Something that ends in _! means "think twice before using this method because it can do something nasty" like Box.open_! or Mapper.delete_!
 


My question is if there is some implied meaning by ending a field in
_! or not?  It seems confusing as a newbie to have that when scala has
an _ operator and a _*.   I got confused with names  like 'dirty_?'
and have to think 'is that an operator of some sort that I need to
lookup or is that just a name?

Thanks,
James


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.






--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

David Pollak

unread,
Jan 8, 2010, 3:14:55 PM1/8/10
to lif...@googlegroups.com

The "_" is required by the Scala parser.  open! is not a valid method name, but open_! is valid.
 

--
                               Jim Wise
                               jw...@draga.com

Jim Wise

unread,
Jan 8, 2010, 3:21:40 PM1/8/10
to lif...@googlegroups.com
David Pollak <feeder.of...@gmail.com> writes:

> The "_" is required by the Scala parser. open! is not a valid method name, but open_! is valid.

Aha!

--
Jim Wise
jw...@draga.com

Gang

unread,
Jan 8, 2010, 4:52:38 PM1/8/10
to Lift
Why is Box.open_! nasty? is it just returning the value held in Box?

Thanks_!

On Jan 8, 3:14 pm, David Pollak <feeder.of.the.be...@gmail.com> wrote:

> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com­>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net

> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Surf the harmonics- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Jim Wise

unread,
Jan 8, 2010, 4:55:08 PM1/8/10
to lif...@googlegroups.com
Gang <wang...@gmail.com> writes:

> Why is Box.open_! nasty? is it just returning the value held in Box?
>
> Thanks_!

Or throwing an exception if the box is not Full()...

--
Jim Wise
jw...@draga.com

Timothy Perrett

unread,
Jan 8, 2010, 7:55:44 PM1/8/10
to lif...@googlegroups.com
It's nasty because it could blow up with either exception or null -
neither of which we like in scala land!

Boxing values keeps things far more managable

Cheers, Tim

Sent from my iPhone

>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/liftweb?hl=en.
>>
>> --
>> Lift, the simply functional web frameworkhttp://liftweb.net
>> Beginning Scalahttp://www.apress.com/book/view/1430219890
>> Follow me:http://twitter.com/dpp
>> Surf the harmonics- Hide quoted text -
>>
>> - Show quoted text -- Hide quoted text -
>>
>> - Show quoted text -

> --
> You received this message because you are subscribed to the Google
> Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com

Reply all
Reply to author
Forward
0 new messages